Shweta
Well-known Member
- Joined
- Jun 5, 2011
- Messages
- 514
Hi All,
I have a table 'LungCapData' with 726 rows. It has 6 columns named as 'LungCap', 'Age', 'Height', 'Smoke', 'Gender', 'Caesarean'.
Below is the query to get the age average for Male and Female for yes and no category of Caesarean.
Below is the result I am getting using above query
<tbody>
</tbody>
My question is why is it not consolidating the results for gender. There should not be multiple results for male and female. I mean the result is not as good as we get in excel pivot tables like below
<tbody>
</tbody>
Kindly help.
Thanks in advance!
Regards,
Shweta Jain
I have a table 'LungCapData' with 726 rows. It has 6 columns named as 'LungCap', 'Age', 'Height', 'Smoke', 'Gender', 'Caesarean'.
Below is the query to get the age average for Male and Female for yes and no category of Caesarean.
Code:
select gender, yes, no
from lungcapdata
pivot
(
avg(age)
for caesarean
in ([yes],[no])
)as pivot1
Below is the result I am getting using above query
gender | yes | no |
female | 3 | NULL |
female | NULL | 3 |
female | NULL | 4 |
male | NULL | 3 |
female | NULL | 5 |
female | NULL | 3 |
male | NULL | 6 |
female | NULL | 8 |
male | NULL | 3 |
female | NULL | 7 |
female | NULL | 8 |
male | 8 | NULL |
male | NULL | 5 |
male | NULL | 7 |
<tbody>
</tbody>
My question is why is it not consolidating the results for gender. There should not be multiple results for male and female. I mean the result is not as good as we get in excel pivot tables like below
<tbody> </tbody> |
<tbody>
</tbody>
Kindly help.
Thanks in advance!
Regards,
Shweta Jain
Last edited: