Commit b1522806 authored by Sorrel Harriet's avatar Sorrel Harriet
Browse files

minor update to queries.sql

parent 9ae08651
......@@ -70,7 +70,7 @@ DELETE FROM Track WHERE album_upc='726517237627'; /* EXAMPLE */
/* ------------------------------------ */
/* 5. Retrieve details about an order
/* 5a. Retrieve details about an order
Include the customer_id, delivery method
and total order value in the result-set */
......@@ -81,3 +81,20 @@ INNER JOIN LineItem
INNER JOIN Album
ON Album.upc=LineItem.album_upc
WHERE Transaction.id=1; /* EXAMPLE */
/* 5b. Retrieve details about an order
Include the transaction id, customer_id
and the number of items ordered in the
result-set */
SELECT t.id, t.customer_id, SUM(li.quantity) AS num_items
FROM Transaction t
INNER JOIN LineItem li
ON t.id=li.trans_id
GROUP BY t.id; /* group results by transaction id */
/* 5c. Does the same as the previous query
but using a nested query rather than a JOIN */
SELECT t.id, t.customer_id,
(SELECT SUM(li.quantity) FROM LineItem li
WHERE li.trans_id=t.id) AS num_items
FROM Transaction t;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment