-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinal SQL Project
More file actions
41 lines (36 loc) · 1.55 KB
/
Final SQL Project
File metadata and controls
41 lines (36 loc) · 1.55 KB
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
#In this SQL, I'm querying a database that's holding Chinook data. Chinook represents a digital media store and includes tables for artists, albums, media tracks, invoices, and customer data.
#1. Show customers who are not in the US.
SELECT FirstName,
LastName,
CustomerID
Country
FROM chinook.customers
WHERE Country <> 'USA';
#2. Find the Invoices of customers who are from Brazil. The resulting table should show the customer's full name, Invoice ID, Date of the invoice, and billing country.
SELECT cust.FirstName,
cust.LastName,
inv.InvoiceId,
inv.InvoiceDate,
inv.BillingCountry
FROM chinook.invoices inv
LEFT JOIN chinook.customers cust
ON inv.CustomerId = cust.CustomerId
WHERE inv.BillingCountry = 'Brazil';
#3. Provide a query that shows the invoices associated with each sales agent. The resulting table should include the Sales Agent's full name.
SELECT emp.FirstName, emp.Lastname, inv.InvoiceId
FROM chinook.Employees emp
JOIN chinook.Customers cust ON cust.SupportRepId = emp.EmployeeId
JOIN chinook.Invoices Inv ON Inv.CustomerId = cust.CustomerId;
#4. How many Invoices were there in 2009?
SELECT COUNT(*)
FROM chinook.Invoices
WHERE InvoiceDate BETWEEN '2009-01-01' AND '2009-12-31';
#5. Provide a query that shows all the Tracks, and include the Album name, Media type, and Genre.
SELECT t.Name AS 'Track Name', a.Title AS 'Album Title', m.Name AS 'Media Type', g.Name AS 'Genre'
FROM chinook.tracks t
JOIN chinook.Albums a
on a.AlbumId = t.AlbumId
JOIN chinook.Media_Types m
on m.MediaTypeId = t.MediaTypeId
JOIN chinook.Genres g
on g.GenreId = t.GenreId;