I have following mysql table as attached in image below. and here is my working query. There are two column which need to be sum on the basis of group by. (Rate and Amount). Currently everything is working fine, but I want to knew is there any way by which I can write just one case statement as it apply on all column which need to be sum ??? is this possible ???
SELECT id, SUM(CASE WHEN subtype in (11, 12) THEN rate ELSE rate END) as ratesum,
SUM(CASE WHEN subtype in (11, 12) THEN Amount ELSE rate END) as amountsum
from test1 GROUP BY id;