Skip to content

sudhirmurthy/SQLTricks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SQLTricks

Pivot and UnPivot Data

  • [PIVOT]

    • The PIVOT relational operator converts data from row level to column level. PIVOT rotates a table-valued expression by turning the unique values from one column in the expression into multiple columns in the output. Using PIVOT operator, we can perform aggregate operation where we need them.
  • [UNPIVOT]

    • UNPIVOT relational operator is reverse process of PIVOT relational operator. UNPIVOT relational operator convert data from column level to row level.
  • [Usecases] Read more about this from this research paper here Read More - Optimization and Execution Strategies in an RDBMS

  • [NOTE:]

      1. I've used an integer datatype to build the default index on the PK.
      1. Uniqueidentifier type for true uniqueness(useful for replication scenarios)
      1. You can use newid() or newsequentialid() for creating a new unique identifiers.For performance reasons, newsequentialid() is preferred.
  • Please refer to the Pivot&UnpivotExample.sql file for more details

About

Pivot and UnPivot Data

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages