Question
Write a query to display the minimum, maximum, and average, and total number of lab tests resulted for patients born in each year between 1990
Write a query to display the minimum, maximum, and average, and total number of lab tests resulted for patients born in each year between 1990 and 2000 and living in California. Display patient year of birth, minimum number of lab tests, maximum number of lab tests, average number of lab tests number of lab tests and total number of lab tests resulted for patients having each birth year. Be sure each field is displayed with a meaningful, user-friendly name. Query needs to be edited to reflect answer.
SELECT DISTINCT(LabResultID),
`p`.`State` AS `State`,
`p`.`Gender` AS `Gender`,
`p`.`YearOfBirth` AS `YearOfBirth`,
`p`.`PatientID` AS `patientId`,
COUNT(`r`.`LabResultID`) AS `NumLabs`,
Min(LabResultID) AS MinLabResults
FROM
(`patients` `p`
JOIN `labresult` `r` ON (`p`.`PatientID` = `r`.`PatientID`))
GROUP BY `p`.`State` , `p`.`Gender` , `p`.`YearOfBirth` , `p`.`PatientID`
Step by Step Solution
3.36 Rating (149 Votes )
There are 3 Steps involved in it
Step: 1
Sql SELECT pYearOfBirth AS BirthYear MINrLabResultID AS MinLabResul...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started