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

 i have table in db as below

deptId   deptName       9      10      11      13      groupName       A       G1       B       C      G2
------  --------       ---     ---     ---     ---     ----------     ----     ---      ---    ----    ---
8	Doctors 	2      	2       0       0       Permanent       0       1       0       0       1
8	Doctors 	2       2       0       0       Apprentice	0	0	0	0	1
     
have any ways to get the table as below

                                                                            Permanent                                 Apprentice
                                                                           -------------                              -----------
deptId   deptName       9      10      11      13      groupName       A       G1       B       C      G2       A      G1       B       C      G2
------  --------       ---     ---     ---     ---     ----------     ----     ---      ---    ----    ---     --      --       --      --     --
8	Doctors 	2      	2       0       0       Permanent       0       1       0       0       1      	0	0	0	0	1


where A,G1,B,C,G2 are the shift in permanent group in a department.

Thanks..
Posted
Updated 3-Feb-14 0:05am
v2
Comments
thatraja 3-Feb-14 5:52am    
Include table structure, sample data in your question
King Fisher 3-Feb-14 7:00am    
not clear

1 solution

I'll get you on your way:

You need to do a join of the table with itself.
You may then select the data from the table by either of the two (or more) versions in a single select clause and they'll come out in a single row.

Now - whether to use inner joins or left/right outer joins is not clear as I don't know what you're trying to show.

It is a common method of transcribing rows in a table to columns in a row.
 
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