Reputation: 7
I need to get the sum of column with two conditions.i.e
example:
Dos Insurance bill_amount
29/11/14 LIC 200
29/11/14 Medicare 300
29/11/14 Selfpay 300
29/11/14 Medicare 400
29/11/14 aetna 900
29/11/14 selfpay 900
29/11/14 Prestige 100
29/11/14 LIC 500
I need the write the query so that I get the view as
dos Total_amount selfpay
29/11/14 2400 1200
Please guide me to wite query
Upvotes: 1
Views: 74
Reputation: 29051
Try this:
SELECT Dos,
SUM(CASE WHEN Insurance != 'Selfpay' THEN bill_amount ELSE 0 END) Total_amount,
SUM(CASE WHEN Insurance = 'Selfpay' THEN bill_amount ELSE 0 END) selfpay
FROM tableA
GROUP BY Dos;
Upvotes: 3