Reputation:
I'm trying to achieve this output
SEX Number
Male 5
Female 7
My code is
SELECT COUNT(CASE WHEN SEX = 'M' then 1 end) as Male, COUNT(CASE WHEN SEX = 'F' then 1 end) as Female FROM EMPLOYEE
The output I'm getting is
MALE FEMALE
5 7
What am I doing wrong? Can someone help?
Upvotes: 0
Views: 1609
Reputation: 1685
Query group by gender using below
SELECT
CASE WHEN Sex ='M' THEN "Male"
WHEN Sex ='F' THEN "Female"
END AS Sex ,
COUNT(*) as Number
FROM OrderDetails
GROUP BY Sex;
Upvotes: 2
Reputation: 11
the problem is that you need to group row's values instead of just count them.
SELECT SEX, COUNT(SEX) FROM EMPLOYEE GROUP BY SEX
Upvotes: 1