Write a query to display the minimum, maximum, and average, and total number of lab tests resulted
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 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`