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

1 Expert Approved Answer
Step: 1 Unlock

Sql SELECT pYearOfBirth AS BirthYear MINrLabResultID AS MinLabResul... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!