Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Ifrah Shahid
lab-exercises
Commits
b1522806
Commit
b1522806
authored
Oct 16, 2016
by
Sorrel Harriet
Browse files
minor update to queries.sql
parent
9ae08651
Changes
1
Hide whitespace changes
Inline
Side-by-side
lab-3/music-store-app/sql/queries.sql
View file @
b1522806
...
...
@@ -70,7 +70,7 @@ DELETE FROM Track WHERE album_upc='726517237627'; /* EXAMPLE */
/* ------------------------------------ */
/* 5. Retrieve details about an order
/* 5
a
. 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
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment