Skip to content
Advertisement

One select statement with multiple Group BY on the same column

I have ‘TABLE_A’ like this:

The goal is to make a groupBy TABLE_A.TVA value and by SUM(TABLE_A.Amount) > 0 and SUM(TABLE_A.Amount) <0, to get finally the sum of all positive Amounts grouped by TVA value, and the sum of all negative amounts grouped by their TVA value also

my Query is like this:

MY question is how to add the second grouping by on negative values, because here i group only on SUM() > 0

Advertisement

Answer

With conditional aggregation:

If you want to include the column TABLE_A.InvoiceID in the grouping then:

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