I have a sample table with below data. i am using Oracle.
ID Sales STATUS
1 100 XX
1 50 XX
1 40 YY
I have to group the data on ID column having different status. I am using below CASE query
SELECT
ID,
sum(sales) SALES,
CASE
WHEN STATUS='XX' THEN 'POSITIVE'
WHEN STATUS='YY' THEN 'NEGATIVE'
END INDICATOR
from
sample_table
group by
ID,
CASE
WHEN STATUS='XX' THEN 'POSITIVE'
WHEN STATUS='YY' THEN 'NEGATIVE'
END;
The above statement is giving me correct output which is
ID SALES INDICATOR
1 150 POSITIVE
1 40 NEGATIVE
Now if i change the data to below
ID Sales STATUS
1 100 XX
1 50 XX
1 40 XX
The query used above is giving only POSITIVE indicator row as there is no YY STATUS in the table. I want to display 0 SALES even if there are no status YY for the same ID.
OUTPUT
ID SALES STATUS
1 190 POSITIVE
Desired output
ID SALES STATUS
1 190 POSITIVE
1 0 NEGATIVE
is it possible to have the desired output? It's a rare scenario for my data but i still want to handle it. Thank you for the help in advance.