~/ 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/f60c9a7a-44f6-425b-954d-bd2a4d92737f/flashcard utf-8 LF