Skip to content
Advertisement

Pivoting but handling Column Names

I’m currently getting a result-set back as follows:

enter image description here

What I’m trying to do is get the results to appear as follows:

enter image description here

I’ve put together the following query, and I was curious as to whether someone had a better way of doing it:

Here’s the sample data:

Advertisement

Answer

You can use conditional aggregation. That is, aggregate functions wrapped around CASE expressions.

For example…

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement