Hi,
Using the CASE syntax and aggregate function SUM in combination, you can write a query as below to get the desired result.
SELECT EmpNo,
Sum(Case MonthNo WHEN 1 then Sal else 0 END) Month_01,
Sum(Case MonthNo WHEN 2 then Sal else 0 END) Month_02,
Sum(Case MonthNo WHEN 3 then Sal else 0 END) Month_03,
Sum(Case MonthNo WHEN 4 then Sal else 0 END) Month_04,
Sum(Case MonthNo WHEN 5 then Sal else 0 END) Month_05,
Sum(Case MonthNo WHEN 6 then Sal else 0 END) Month_06,
Sum(Case MonthNo WHEN 7 then Sal else 0 END) Month_07,
Sum(Case MonthNo WHEN 8 then Sal else 0 END) Month_08,
Sum(Case MonthNo WHEN 9 then Sal else 0 END) Month_09,
Sum(Case MonthNo WHEN 10 then Sal else 0 END) Month_10,
Sum(Case MonthNo WHEN 11 then Sal else 0 END) Month_11,
Sum(Case MonthNo WHEN 12 then Sal else 0 END) Month_12
FROM EmpSalary
group by EmpNo
Cheers,
Pooja Falor
