Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I separate two genders from the same column and use them separately?

I have a table where one column has the genders (M,F,O) and I have another column for patient_weight, I need to get the average weight of the Females and then show a count of all the males that weigh less than the average female. Here is what I have so far:

SELECT top 50 * 
FROM 
    dbo.patients

SELECT
    AVG(patient_weight)
FROM 
    patients
WHERE gender LIKE 'F';

SELECT
COUNT
    (patient_weight)
FROM 
    patients
WHERE gender LIKE 'M' AND patient_weight < 77

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

As the query with the female average weight will return a scalar value. you can use it directy as criteria for the weight of the male patients

SELECT
COUNT(*) number_of_malepatients_below_avg
FROM 
    patients
WHERE gender LIKE 'M' AND patient_weight < (SELECT
    AVG(patient_weight)
FROM 
    patients
WHERE gender LIKE 'F');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading