YOUR AD GOES HERE

day 43 | 50 Days of SQL | SELECT, AS, FROM, JOIN ON, GROUP BY, HAVING, SUM() | SQL QUERY

Published 08, Dec 2023

SAHAS H S


Description:
Identifying Provinces with More Male Patients than Female


Your task is to write a SQL query to answer the following question. Show the provinces that have more patients identified as 'M' than 'F'. You should only display the full province_name.

Database Information
You will be working with a database. The relevant tables for this exercise are:

patients
province_names
You are encouraged to explore the structure of these tables to understand their relationships and the data they contain.

Important Concepts
Joins: You'll need to join multiple tables to gather all the necessary data.
Aggregate Functions: These functions allow you to perform calculations on a group of rows, potentially subdividing them based on the values of one or more columns. For this exercise, understanding how to count rows based on certain conditions will be crucial.
Grouping: It's essential to group your results by certain columns to aggregate data correctly.
Having Clause: Once you've grouped your results, you might want to filter them based on the aggregated data.
Make sure the column name is province_name

Remember to think critically about each step in your query, and ensure your final output matches the question's requirements. Good luck!

select province_names.province_name
from province_names join patients on province_names.province_id=patients.province_id group by province_names.province_id having sum(case when patients.gender='M' then 1 else 0 end)[GREATER THAN]sum(case when patients.gender='F' then 1 else 0 end)
#codedamn #challenge #solution #sql #50dayschallenge #query #syntax

Releted More Videos

You May Also Like

YOUR AD GOES HERE

YOUR AD GOES HERE