-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queries.txt
46 lines (40 loc) · 869 Bytes
/
Queries.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* Query 1 */
SELECT i.BillingCountry, COUNT(il.trackid) no_of_tracks
FROM Invoice i
JOIN InvoiceLine il
ON i.InvoiceId = il.InvoiceId
GROUP By 1
ORDER By 2 DESC
LIMIT 10;
/* Query 2 */
SELECT g.Name genre_name, SUM(il.Quantity) tot_sales
FROM Genre g
JOIN Track t
ON g.GenreId = t.GenreId
JOIN InvoiceLine il
ON il.TrackId = t.TrackId
GROUP BY genre_name
ORDER BY 2 DESC
LIMIT 5;
/* Query 3 */
SELECT a.Title album_name, SUM(il.UnitPrice*il.Quantity) album_sales
FROM Album a
JOIN Track t
ON t.AlbumId = a.AlbumId
JOIN InvoiceLine il
ON il.TrackId = t.TrackId
GROUP BY 1
ORDER BY 2 DESC
LIMIT 15;
/* Query 4 */
SELECT a.name artist_name, SUM(il.Quantity*il.UnitPrice) money_earned
FROM InvoiceLine il
JOIN Track t
on il.TrackId = t.TrackId
JOIN Album al
on al.AlbumId = t.AlbumId
JOIN Artist a
on al.ArtistId = a.ArtistId
GROUP BY 1
ORDER BY 2 DESC
LIMIT 15;