Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all ,

i have records like this.


ID TYPE

1 0
1 1
1 2
2 1
2 2

now i would like to have a query which gives me out put like this .


ID Type1 TYPE2 TYPE3

1 TRUE TRUE TRUE
2 FALSE TRUE TRUE

i tried some group by kind of things but not applied as my table have multiple joins and some where conditions as well so i can not put the whole code. above is just the basic thing which i want to do.
Posted

1 solution

Use PIVOT[^] like this:
SQL
SELECT id, [0], [1], [2]
FROM (SELECT id, [type] FROM mytable) AS src
PIVOT (COUNT([type]) FOR [type] IN ([0],[1],[2])) AS pvt

You can optionally rename the columns or replace 0/1 with TRUE/FALSE.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900