Forum Discussion
rameshdv
Jun 28, 2021Copper Contributor
Pivot sql
Hi All, I need help with a sql on how to write a pivot sql for the working sql. SELECT DEPTID,JRNL_LINE_SOURCE, SUM(MONETARY_AMOUNT) 'Sum Amount' FROM PS_JRNL_LN WHERE BUSINE...
- Jun 28, 2021
rameshdv , an easy way is to use conditional summing, like
select Dept, sum(case when Type = 'GAP' THEN MONETARY_AMOUNT ELSE 0.0 END) AS Gap, sum(case when Type = 'GEX' THEN MONETARY_AMOUNT ELSE 0.0 END) AS Gex from yourTable where .. group by Dept
olafhelper
Jun 28, 2021Bronze Contributor
rameshdv , an easy way is to use conditional summing, like
select Dept,
sum(case when Type = 'GAP' THEN MONETARY_AMOUNT ELSE 0.0 END) AS Gap,
sum(case when Type = 'GEX' THEN MONETARY_AMOUNT ELSE 0.0 END) AS Gex
from yourTable
where ..
group by Deptrameshdv
Jun 29, 2021Copper Contributor
Hi olafhelper,
Thanks a lot for the help.
Thanks a lot for the help.