I want to use multiple conditions within a single WHEN but it return error 'not a single-group group function' I use Oracle SQL Developer
SELECT
CASE WHEN (TB2.BENE_CODE NOT LIKE '%ET%') AND (SUM(TB2.APPROVE_TOTAL)
> 0) THEN SUM(TB2.APPROVED_TOTAL)
ELSE 0 END AS Total_PayAmount
FROM clm_header_tr TB1
result is ORA-00937: not a single-group group function
I try to separate condition with () but it doesn't work.
So What is the root cause? How can I resolve it? Thank you.
You shoud sum() around case, not inside:
If you want to compare aggregate data and certain field data, then you should firstly do a subquery that uses analytic variant:
sum() over (), it will show aggregated data on each field and then you can use it in case.