Skip to content
Advertisement

Generate Monthly Aggregated Values in SQlite

I am new in SQLite and i have been working on SQL Query for quite some time.

Lets say we have database table say tbl_expense with the following table structure.

tbl_expense

Assume we have the following data stored in the table.

enter image description here

Expected Output

Assuming we have expense_date as timestamp, How can i write a SQL query in such a way that i can produce the output like the one below.

enter image description here

Please help me on this issue.

Advertisement

Answer

You need a LEFT join of a cte that returns all the month abbreviations to the table and conditional aggregation:

The condition:

is used to return results only for the current year.
You can change it to get results for any year that you want, like:

See the demo.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement