How to access the sum of a column in my sqlite database in flask

Viewed 30

Sorry if the title is not a good description. I am build a spending tracker flask app. I have a database which has the amount I am spending and the type of spending it is. https://i.stack.imgur.com/lAakV.png. I also have a way of adding new spending through my flask app https://i.stack.imgur.com/x0dZf.png. My issue is that I want to be able to access the sum of the spending_amoount in flask and send it to my html page. I left the education_total and transportation_total blank, that blank is where I want to access the sum of their respective spending_amount.

1 Answers

You probably want to execute a group by statement.

For your database it would look like that:

SELECT spending_type, sum(spending_amount) FROM <YourTableName> GROUP BY spending_type
Related