dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: SQL
Expertise: Advanced
Jul 19, 2016

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


PIVOTing Data in SQL

You can use the PIVOT SQL command to transpose Row data into Column data. This means that you can take a set of rows and make fields out of them! Each row in the results table (based on the particular query / data) will represent a field. In this next small example, I have pivoted 6 fields (RowField1 - RowField6) depending on the first table's Field values:

SELECT DISTINCT * FROM (
SELECT Field1, Field2, Field3

FROM [Table]

) a

PIVOT(
MIN(Field2)
FOR a.Field1 IN (RowField1,
RowField2,
RowField3,
RowField4,
RowField5,
RowField6)
) AS b
WHERE b.RowField3 = 'TEST'
Hannes du Preez
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date