PIVOT in SQL:-
- Pivot help us to transform or display data row to column level.
- It help us to generate Multidimensional report.
- We can generate Month & Year wise summary of large data.
Query as below: -
Select * from CustomerData
SELECT *
FROM (
SELECT name, mobileno, left(datename(month,dtDate),3)as [month], amount FROM CustomerData
) as s
PIVOT
(
SUM(amount)
FOR [month] IN (jan, feb, mar, apr,
may, jun, jul, aug, sep, oct, nov, dec)
)AS pvt
Query output as below:-
No comments:
Post a Comment