Skip to content
Advertisement

SQL Group By Sum and Nulls

I have a query that fetch the sum of quantity of a certain date with a GROUP BY, but the query is giving me NULL results and not aggregating some values.

Here is the query:

How can I aggregate the result to only show per year?

I’m using MS SQL

Advertisement

Answer

I suspect you want conditional aggregation:

Note that VP.combustivel is not in the GROUP BY.

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