~/ learn/ comp-378/ cards/ Derived Tables & CASE Expressions
1 of 5

Type the derived-table-in-FROM pattern:

Type the derived-table-in-FROM pattern:

Answer

SELECT p.name, p.price, a.avg_price FROM products p CROSS JOIN (SELECT AVG(price) AS avg_price FROM products) AS a WHERE p.price > a.avg_price;

The parenthesized SELECT in FROM is the derived table a (one row, the average); CROSS JOIN attaches it to every product so the average can be both compared and displayed.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/53fb2b25-159f-4ad4-8019-44020c6aa8ed/flashcard utf-8 LF