If you’ve been writing SQL for a while, you’ve probably run into situations where you need to query data that’s already been aggregated, filtered, or transformed in some way. Maybe you need to calculate an average first, then find all the rows above that average. Or perhaps you need to group data by category, then filter those grouped results.
This is where derived tables can come in handy. Derived tables let you build queries in layers, where one query’s output becomes another query’s input, all within a single SQL statement.