Consideration to move questions into a new section: nested queries
joshkyh opened this issue · comments
In https://swcarpentry.github.io/sql-novice-survey/06-agg/
[What does this query do?] In order to find the differences of individual readings with the individual's average reading, I think we'd require nesting the query in the following manner:
SELECT S.* , AV.avg_reading , S.reading - AV.avg_reading AS diff_reading FROM Survey S INNER JOIN (SELECT person, quant, AVG(reading) AS avg_reading FROM Survey GROUP BY person, quant) AV ON S.person = AV.person AND S.quant = AV.quant ;
At this stage, nesting is not introduced, and I think nesting deserves a new section by itself given its usefulness.
I think the next question [Ordering When Concatenating] also has the same issue (requires nesting).
Sorry, wrong repo. I'll resubmit this to the SQL repo.