-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueries.txt
More file actions
35 lines (32 loc) · 1015 Bytes
/
Queries.txt
File metadata and controls
35 lines (32 loc) · 1015 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
/*Query 1 to answer the question on "What is the most Media Type do we have?"*/
SELECT m.Name, COUNT(t.MediaTypeId) AS MediaTypeCount
FROM MediaType m
JOIN Track t
ON m.MediaTypeId = t.MediaTypeId
GROUP BY m.Name
ORDER BY 2 DESC;
/*Query 2 to answer the question on "Who are our best 3 Customers?" */
SELECT (c.FirstName || " " || c.LastName) AS CustomerName,
SUM(i.total) AS TotalSales
FROM Customer c
JOIN Invoice i
ON c.CustomerId = i.CustomerId
GROUP BY 1
ORDER BY 2 DESC
LIMIT 3;
/* Query 3 to answer the question on "Who is our best performing Support Rep?"*/
SELECT (e.FirstName || " " || e.LastName) AS RepName,
COUNT(c.SupportRepId) AS CustomersSupported
FROM Employee e
JOIN Customer c
ON e.EmployeeId = c.SupportRepId
GROUP BY 1
ORDER BY 2;
/* Query 4 to answer the question on "What are the Top 10 selling Tracks?"*/
SELECT t. Name, SUM(i.Quantity) AS QuantityOrdered
FROM Track t
JOIN InvoiceLine i
ON t.TrackId = i.TrackId
GROUP BY 1
ORDER BY 2 DESC
LIMIT 10;