Writing a SQL data aggregation query

Hi Guys,

I need help in writing SQL data aggregation query to create the data summary extract see pic attached. I have limited SQL knowledge only basic select, left joins, filtering, etc.. and I'm trying together better with joins and aggregation. Any help would be appreciated.. thanks!

Hi juggin95,

Aggregation is not that hard however it can become complicated. Try to find out the diffrence between the WHERE and HAVING clausule and understand grouping. Google will be your friend to find examples.

SELECT
C.Lastname,
COUNT(*) AS NumberOfPatient,
MAX(patient_id) AS MaxPatientID,
MIN(patient_id) AS MinPatientID,
AVG(patient_id) AS AvgPatientID
FROM consultants C
INNER JOIN fce
ON C.id=fce.consultant_id
GROUP BY
C.LastName

I think you will like this video on youtube

Thank you, this worked like a charm and the video was really useful!!