Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

I have a table like this...

CustomerID   DBColumnName   Data

--------------------------------------

1            FirstName      Joe

1            MiddleName     S

1            LastName       Smith

1            Date           12/12/2009

2            FirstName      Sam

2            MiddleName     S

2            LastName       Freddrick

2            Date           1/12/2009

3            FirstName      Jaime

3            MiddleName     S

3            LastName       Carol

3            Date           12/1/2009

And I want this...

Is this possible using PIVOT?

CustomerID  FirstName   MiddleName          LastName        Date

----------------------------------------------------------------------

1           Joe             S               Smith           12/12/2009

2           Sam             S               Freddrick       1/12/2009

3           Jaime           S               Carol           12/1/2009

1 Answer

0 votes
by (40.7k points)

You can try using the MAX aggregate, it will work. 

If MAX of one value = that particular value...

In the above case, you can self join 5 times on customerid, which can be filtered by dbColumnName per table reference.

Related questions

0 votes
1 answer
asked Jul 11, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Nov 21, 2020 in SQL by Appu (6.1k points)

Browse Categories

...