C# Corner
Tech
News
Videos
Forums
Trainings
Books
Events
More
Interviews
Jobs
Live
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
.NET
ADO.NET
Android
ASP.NET
C#
Databases & DBA
Design Patterns & Practices
Java
Learn iOS Programming
OOP/OOD
SharePoint
Software Testing
Web Development
WPF
View All
1
Reply
What is pivot table and unpivot table?
Ramesh Joshi
9y
671
0
Reply
Delete Row
Delete Column
Insert Link
×
Insert
Cancel
Embed YouTube Video
×
Width (%)
Height (%)
Insert
Cancel
Table Options
×
Rows
Columns
First row as header
Create Table
Insert Image
×
Selected file:
Alignment
Left
Center
Right
Select an image from your device to upload
Upload to Server
Cancel
Submit
Pivot tables -are used to summarize and display the data, specially in case of report data by means of aggregating the values. Pivot table can be used if we want to display the unique values of the column of a table as the columns of another table. It turns the unique values of a specified column into another table columns. SELECT non-pivoted column,firstpivotedcolumn AS column name,secondpivotedcolumn AS column name,lastpivotedcolumn AS column name FROM(SELECT query that produces the data>)AS aliasforsourcequery PIVOT (aggregation function(column being aggregated) FOR column that contains the values that will become column headersIN ( firstpivotedcolumn,secondpivotedcolumn,last pivoted column) ) AS aliasforthepivottable (optional ORDER BY clause) Unpivot table:- Unpivot table is reverse of Pivot table as it rotate the columns of a table into the value of a column. For example, suppose we have a table say tbl_stdmarksdata whose structure us given below:-Create table tbl_stdmarksdata (studentname nvarchar(100), I int, II int, III int, IV int, V int)Query for inserting data in this table is given below:-Insert into tbl_stdmarksdata (studentname,I,II,III,IV,V) Select 'Vivek Johari',30,20,35, 40, 45 Union All Select 'Chandra Singh',30,20,35,44, 80 Union All Select 'Avinash Dubey',30,25,35,20, 39 Union All Select 'Pankaj Kumar',33,29,30, 60, 50After insert, the data in the table :-select * from tbl_stdmarksdata The Query for the Unpivot table will be as follow:-select studentname,Marks,Grade from tbl_stdmarksdata unpivot (Marks for Grade in (I,II,III,IV,V) ) as tblunpvt
Ramesh Joshi
9y
0
Message