Queries with derived tables (I)
The focus of this lesson is derived tables. You can use derived tables when you want to break down a complex query into smaller steps. A derived table is a query which is used in the place of a table. Derived tables are a great solution if you want to create intermediate calculations that need to be used in a larger query.
In this exercise, you will calculate the maximum value of the blood glucose level for each record by age.
Latihan ini adalah bagian dari kursus
Intermediate SQL Server
Petunjuk latihan
- Return
MaxGlucosefrom the derived table. - Join the derived table to the main query on
Age.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
SELECT a.RecordId, a.Age, a.BloodGlucoseRandom,
-- Select maximum glucose value (use colname from derived table)
b.___
FROM Kidney a
-- Join to derived table
___ (SELECT Age, MAX(BloodGlucoseRandom) AS MaxGlucose FROM Kidney GROUP BY Age) b
-- Join on Age
___