0

how can i count the value of two different column in database?

example:

i have a table hospital which have a column , hosptal_id and sex

now i want a result that count the the sex column by type, (male or female) within a hospital

i want the result something like..

hospital_id ------ F ------ M

1 ----------------- 14----- 45

2 ----------------- 23----- 49

3 ----------------- 29------ 76

, how can i get this result?

is anybody can help me on this?

0

2 Answers 2

2
SELECT id,SUM(IF(sex='M',1,0)) AS 'male', 
SUM(IF(sex='F',1,0)) AS 'female' 
FROM hospital 
GROUP BY id
Sign up to request clarification or add additional context in comments.

Comments

0

Try query like this--

SELECT COUNT(DISTINCT column_name) AS some_alias FROM table_name

1 Comment

i want to count the value of sex individually.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.