Question: For each of the subquery types in Chapter 7, write a similar query on the sakila database. Include the English query, the SQL query, and
For each of the subquery types in Chapter 7, write a similar query on the sakila database. Include the English query, the SQL query, and the result set.
- Subquery using an aggregate function (AVG, SUM, MIN, MAX, COUNT) (see fig 7-1 p 201)
- Subquery using IN phrase (fig 7-3 p 205)
- Subquery with a comparison operator (fig 7-4, p 207)
- Subquery using ALL (7-5, p 209)
- Subquery using ANY (7-6, p 211)
- Subquery using EXISTS (7-8, p 215)
- Subquery in SELECT clause (7-9, p 217)
- Subquery in FROM clause (7-10, p 219)
- Complex query with multiple subqueries (7-11, p 221)
Subquery in WHERE using Aggregate Function SELECT invoice number, invoice date, invoice total FROM invoices WHERE invoice total > (SELECT AVG (invoice total) FROM invoices) ORDER BY invoice total The value returned by the subquery 1879.741316 The result set Invoice number 989319-487 97/522 989319-417 989319-427 989319-477 587056 invoice_date 2018-06-20 2018-06-28 2018-07-23 2018-06-16 2018-06-08 2018-06-30 invoice total 1927.54 1962. 13 2051.59 2115.81 2184.11 2184.50 (21 rows) Subquery in WHERE using Aggregate Function SELECT invoice number, invoice date, invoice total FROM invoices WHERE invoice total > (SELECT AVG (invoice total) FROM invoices) ORDER BY invoice total The value returned by the subquery 1879.741316 The result set Invoice number 989319-487 97/522 989319-417 989319-427 989319-477 587056 invoice_date 2018-06-20 2018-06-28 2018-07-23 2018-06-16 2018-06-08 2018-06-30 invoice total 1927.54 1962. 13 2051.59 2115.81 2184.11 2184.50 (21 rows)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
