Skip to content
Advertisement

ORA-00937 not a single-group group function when using CASE Condition

I’ve been searching for a few hours now, on how to resolve an ORA-00937: not a single-group group function and none of them seem to explain why I am getting the error. My understanding is, when applying an aggregate function in the select statement on one or more columns, than you should include the columns that are not aggregated in the select by statement. I’ve done that, however the error always occurs at line 2, column 9 which is where the c.data_entry_date is located on the second line below. This error only occurs when I apply the logic from this portion of the query:

If I were to comment that specific CASE logic, then the query runs successfully. That being said, the CASE logic is fairly new to me. I’ve tried some creative Googling to try to find some sort of solution. I’ve played around with various columns in the group by and I can’t see to get it to work. I’m wondering if the aggregation of SUM in that CASE logic using, the c.data_entry_date column is conflicting with how I used it in the first column in the SELECT statement? Here’s my broader code if anyone wants to tackle a solution:

Much appreciated!

Advertisement

Answer

Remove the sum() in the then clauses. They case is already the argument of a sum(). There is no need to do a sum() within a sum() — it is not allowed.

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