How can I get the count for the sex(Male, Female) and total in the columns?
i want this in below format how is that possible in Sql.
How can I get the count for the sex(Male, Female) and total in the columns?
i want this in below format how is that possible in Sql.
You can use a eg: sum of case when
select sum(case when sex = 'Female' then 1 else 0 end) Female,
sum(case when sex = 'Male' then 1 else 0 end) Male,
sum(case when sex = 'Female' then 1 else 1 end) Total
from my_table
Since you did not provide any other details like the table name, my best effort for you will be something like the following code, This is written in MySql syntax, but I'm sure that in other SQL it will be similar.
SELECT
IF(Sex = 'Female', Count, 0) AS Female,
IF(Sex = 'Male', Count, 0) AS Male,
SUM(Count) AS Total
FROM
[TableName]
;