-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject Queries.sql
More file actions
45 lines (39 loc) · 925 Bytes
/
Project Queries.sql
File metadata and controls
45 lines (39 loc) · 925 Bytes
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
/*Question 1:who is the Best Customer?*/
SELECT (c.FirstName || " " || c.LastName) AS Customer,
SUM(i.Total) 'Total$'
FROM Invoice i
JOIN Customer c
ON i.CustomerId = c.CustomerId
GROUP BY 1
ORDER BY 2 DESC
LIMIT 10;
/*Question 2:What are the most Profitable Genres?*/
SELECT g.Name AS Genre,
ROUND(SUM(il.UnitPrice * il.Quantity), 2) AS Profit
FROM InvoiceLine il
JOIN Track t
ON t.TrackId = il.TrackId
JOIN Genre g
ON t.GenreId = g.GenreId
GROUP BY 1
ORDER BY 2 DESC
LIMIT 10;
/* Question 3:What is the Album Length distribution?*/
SELECT al.Title Album,
ROUND(SUM(t.Milliseconds)/1000, 2) 'Length(sec)'
FROM Album al
JOIN Track t
ON al.AlbumId = t.AlbumId
GROUP BY 1
ORDER BY 2 DESC;
/*#Question 4:Who is writing the most Songs?*/
SELECT ar.Name,
COUNT(t.TrackId) Songs
FROM Artist ar
JOIN Album al
ON ar.ArtistId = al.ArtistId
JOIN Track t
ON t.AlbumId = al.AlbumId
GROUP BY 1
ORDER BY 2 DESC
LIMIT 10;