forked from cabritavazquez/15-sql_queries_02-chinook
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
129 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,44 @@ | ||
# 15-sql_queries_02-chinook | ||
Chinook SQL exercise | ||
### More SQL query fun from the fine folks who brought you the previous SQL exercises. | ||
Let's cement your SQL query bonafides with a tougher test of your new skills. Keep the Chinook db handy... | ||
|
||
## Requirements | ||
Use the [Chinook Database](https://chinookdatabase.codeplex.com/) and the [DB Browser for SQLite](http://sqlitebrowser.org/) we downloaded in the ERD exercise. | ||
|
||
For each of the following exercises, provide the appropriate query. | ||
|
||
Keep your successful queries in a `chinook-queries.sql` file. | ||
|
||
1. Provide a query showing Customers (just their full names, customer ID and country) who are not in the US. | ||
2. Provide a query only showing the Customers from Brazil. | ||
3. Provide a query showing the Invoices of customers who are from Brazil. The resultant table should show the customer's full name, Invoice ID, Date of the invoice and billing country. | ||
4. Provide a query showing only the Employees who are Sales Agents. | ||
5. Provide a query showing a unique list of billing countries from the Invoice table. | ||
6. Provide a query showing the invoices of customers who are from Brazil. | ||
7. Provide a query that shows the invoices associated with each sales agent. The resultant table should include the Sales Agent's full name. | ||
8. Provide a query that shows the Invoice Total, Customer name, Country and Sale Agent name for all invoices and customers. | ||
9. How many Invoices were there in 2009 and 2011? What are the respective total sales for each of those years? | ||
10. Looking at the InvoiceLine table, provide a query that COUNTs the number of line items for Invoice ID 37. | ||
11. Looking at the InvoiceLine table, provide a query that COUNTs the number of line items for each Invoice. HINT: [GROUP BY](http://www.sqlite.org/lang_select.html#resultset) | ||
12. Provide a query that includes the track name with each invoice line item. | ||
13. Provide a query that includes the purchased track name AND artist name with each invoice line item. | ||
14. Provide a query that shows the # of invoices per country. HINT: [GROUP BY](http://www.sqlite.org/lang_select.html#resultset) | ||
15. Provide a query that shows the total number of tracks in each playlist. The Playlist name should be include on the resultant table. | ||
16. Provide a query that shows all the Tracks, but displays no IDs. The resultant table should include the Album name, Media type and Genre. | ||
17. Provide a query that shows all Invoices but includes the # of invoice line items. | ||
18. Provide a query that shows total sales made by each sales agent. | ||
19. Which sales agent made the most in sales in 2009? | ||
20. Which sales agent made the most in sales in 2010? | ||
21. Which sales agent made the most in sales over all? | ||
22. Provide a query that shows the # of customers assigned to each sales agent. | ||
23. Provide a query that shows the total sales per country. Which country's customers spent the most? | ||
24. Provide a query that shows the most purchased track of 2013. | ||
25. Provide a query that shows the top 5 most purchased tracks over all. | ||
26. Provide a query that shows the top 3 best selling artists. | ||
27. Provide a query that shows the most purchased Media Type. | ||
|
||
#### Other Resources | ||
* http://www.sqlcourse.com/ | ||
* https://github.com/treehouse/cheatsheets/blob/master/sql_basics/cheatsheet.md | ||
* [SQL Cheatsheet](https://zeroturnaround.com/wp-content/uploads/2016/06/RebelLabs-SQL-cheat-sheet.png) | ||
* http://www.sqlite.org/lang_select.html | ||
* https://www.sololearn.com/Course/SQL/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
-- 1. Provide a query showing Customers (just their full names, customer ID and country) who are not in the US. | ||
select customerid, firstname, lastname, country | ||
from customer | ||
where not country = 'USA'; | ||
|
||
-- 2. Provide a query only showing the Customers from Brazil. | ||
select * from customer | ||
where country = 'Brazil'; | ||
|
||
-- 3. Provide a query showing the Invoices of customers who are from Brazil. The resultant table should show the customer's full name, Invoice ID, Date of the invoice and billing country. | ||
select c.firstname, c.lastname, i.invoiceid, i.invoicedate, i.billingcountry | ||
from customer as c, invoice as i | ||
where c.country = 'Brazil' and | ||
c.customerid = i.customerid; | ||
|
||
-- 4. Provide a query showing only the Employees who are Sales Agents. | ||
|
||
|
||
-- 5. Provide a query showing a unique list of billing countries from the Invoice table. | ||
|
||
|
||
-- 6. Provide a query showing the invoices of customers who are from Brazil. | ||
|
||
|
||
-- 7. Provide a query that shows the invoices associated with each sales agent. The resultant table should include the Sales Agent's full name. | ||
|
||
|
||
-- 8. Provide a query that shows the Invoice Total, Customer name, Country and Sale Agent name for all invoices and customers. | ||
|
||
|
||
-- 9. How many Invoices were there in 2009 and 2011? What are the respective total sales for each of those years? | ||
|
||
|
||
-- 10. Looking at the InvoiceLine table, provide a query that COUNTs the number of line items for Invoice ID 37. | ||
|
||
|
||
-- 11. Looking at the InvoiceLine table, provide a query that COUNTs the number of line items for each Invoice. HINT: [GROUP BY](http://www.sqlite.org/lang_select.html#resultset) | ||
|
||
|
||
-- 12. Provide a query that includes the track name with each invoice line item. | ||
|
||
|
||
-- 13. Provide a query that includes the purchased track name AND artist name with each invoice line item. | ||
|
||
|
||
-- 14. Provide a query that shows the # of invoices per country. HINT: [GROUP BY](http://www.sqlite.org/lang_select.html#resultset) | ||
|
||
|
||
-- 15. Provide a query that shows the total number of tracks in each playlist. The Playlist name should be include on the resultant table. | ||
|
||
|
||
-- 16. Provide a query that shows all the Tracks, but displays no IDs. The resultant table should include the Album name, Media type and Genre. | ||
|
||
|
||
-- 17. Provide a query that shows all Invoices but includes the # of invoice line items. | ||
|
||
|
||
-- 18. Provide a query that shows total sales made by each sales agent. | ||
|
||
|
||
-- 19. Which sales agent made the most in sales in 2009? | ||
|
||
|
||
-- 20. Which sales agent made the most in sales in 2010? | ||
|
||
|
||
-- 21. Which sales agent made the most in sales over all? | ||
|
||
|
||
-- 22. Provide a query that shows the # of customers assigned to each sales agent. | ||
|
||
|
||
-- 23. Provide a query that shows the total sales per country. Which country's customers spent the most? | ||
|
||
|
||
-- 24. Provide a query that shows the most purchased track of 2013. | ||
|
||
|
||
-- 25. Provide a query that shows the top 5 most purchased tracks over all. | ||
|
||
|
||
-- 26. Provide a query that shows the top 3 best selling artists. | ||
|
||
|
||
-- 27. Provide a query that shows the most purchased Media Type. |