I want to pivot my table with multiple columns as per below requirement.
Employee_ID ProcessingMonth Amount FinancialYear
3 April 41668.00 2017
3 June 41668.00 2017
3 March 41668.00 2017
3 May 41668.00 2017
4 April 10037.92 2017
4 June 10037.92 2017
4 March 10037.92 2017
4 May 10037.92 2017
i want result like below
Employee_ID year jan feb mar apr may june jul aug sep oct nov dec
3 2017 0 0 41668.00 41668.00 41668.00 41668.00 0 0 0 0 0 0
4 2017 0 0 10037.92 10037.92 10037.92 10037.92 0 0 0 0 0 0
Try this:
SELECT *
FROM (
SELECT
SUM(Amount) AS sum_amount
, Employee_ID
, FinancialYear
, ProcessingMonth
FROM your_table
GROUP BY
Employee_ID
, FinancialYear
, ProcessingMonth
) t
PIVOT (SUM(sum_amount)
FOR ProcessingMonth IN (
[January], [February], [March], [April], [May], [June], [July], [August], [September], [October], [November], [December])
) AS pvt;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With