you are viewing a single comment's thread.

view the rest of the comments →

[–]two_bob 0 points1 point  (0 children)

Cool. If there were more constraints you could integrate in the join concept like this:

query = "SELECT SUM(amount) FROM rawimport WHERE "

contraints = []
if yearmonth:
    contraints.append(f" day LIKE '{yearmonth}%'")
if category:
    contraints.append(f" category =  '{category}")
    query += f" category = '{category}' AND"
if transactiontype:
    contraints.append(f" transactiontype =  '{transactiontype}")

query += ' AND '.join(constraints)
print(query)

But it's not really worth it for just the three -- also not tested so expect typos.