I am just facing trouble to sort out the query I need. I have a scenario like this
colDist colGender attnedancePrcnt
Place-1 Male 2.5 %
Place-1 Female 1.5%
Place-2 Male 3.5%
Place-2 Female 2.1%
Now I need a query in mysql to have the data like this
colDist colMale colFemale
Place-1 2.5% 1.5 %
Place-2 3.5% 2.1 %
This is sort of group by coldDist but I am just facing trouble to make the colMale and colFemale from the first data set into the second one.
Advance thanks.
This approach.....
select colDist, if(colGender='Male',colGender,null ) as colMale ,
if(colGender='Female',colGender,null ) as colFemale
from tablename
gives me the result like this
colDist colMale colFemale attnedancePrcnt
Place-1 Male NULL 2.5
Place-1 NULL Female 1.5
Place-2 Male NULL 3.5
Place-2 NULL Female 2.1
But again I need them like this:
colDist colMale colFemale
Place-1 2.5% 1.5 %
Place-2 3.5% 2.1 %
So how can I group or pivot the data as required?
Thanks.