Show the provinces that has more patients identified as ‘M’ than ‘F’. Must only show full province_name
patient table :
patient_id INT
first_name TEXT
last_name TEXT
gender CHAR(1)
birth_date DATE
city TEXT
province_id CHAR(2)
allergies TEXT
height INT
weight INT
Province_names table:
province_id CHAR(2)
province_name TEXT
I tried this but it’s not working.
`select province_name
from patients p,province_names pn
where p.province_id = pn.province_id
and (count(p.province_id) group by p.patient_id having p.gender = 'M' ) >
(count(p.province_id) group by p.patient_id having p.gender = 'F') `
3
Answers
Aggregation provides one straightforward approach:
I think your problem is solved by this query
You can USE CTE to achieve your goal if your MySQL version is 8.0.X.X and more!!
(Run this command to check it:)
Full Code: