Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feb 24 #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions brazil_customers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT *
FROM Customer
WHERE Country == "Brazil"
3 changes: 3 additions & 0 deletions brazil_customers_invoices.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT FirstName, LastName, InvoiceId, InvoiceDate, BillingCountry
FROM Customer JOIN Invoice ON Customer.CustomerId == Invoice.CustomerId
WHERE Country == "Brazil"
3 changes: 3 additions & 0 deletions country_invoices.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT Invoice.BillingCountry,Count(*)
FROM Invoice
GROUP BY Invoice.BillingCountry
3 changes: 3 additions & 0 deletions invoice_37_line_item_count.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT Count(*)
FROM InvoiceLine
WHERE InvoiceId = 37
4 changes: 4 additions & 0 deletions invoice_totals.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT Employee.FirstName ||" "|| Employee.LastName AS "Employee Name" , Customer.FirstName ||" "|| Customer.LastName AS "Customer Name", Invoice.Total, Invoice.BillingCountry
FROM Employee
JOIN Customer ON Customer.SupportRepId == Employee.EmployeeId
JOIN Invoice ON Invoice.CustomerId == Customer.CustomerId
Empty file added invoices_line_item_count.sql
Empty file.
3 changes: 3 additions & 0 deletions line_item_track.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT InvoiceLine.InvoiceId, Track.TrackId, Track.Name
FROM InvoiceLine
JOIN Track ON InvoiceLine.TrackId = Track.TrackId
5 changes: 5 additions & 0 deletions line_item_track_artist.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT InvoiceLine.InvoiceId, Track.TrackId, Track.Name, Artist.Name
FROM InvoiceLine
JOIN Track ON InvoiceLine.TrackId = Track.TrackId
JOIN Album ON Track.AlbumId = Album.AlbumId
JOIN Artist ON Album.ArtistId = Artist.ArtistId
3 changes: 3 additions & 0 deletions line_items_per_invoice.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT Count(*) AS InvoiceIdNumber
FROM InvoiceLine
GROUP BY InvoiceId
3 changes: 3 additions & 0 deletions non_usa_customers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT FirstName, LastName, CustomerId
FROM Customer
WHERE Country != "USA"
4 changes: 4 additions & 0 deletions playlists_track_count.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT Playlist.PlaylistId, Playlist.Name, Count(*)
FROM PlaylistTrack
JOIN Playlist ON Playlist.PlaylistId = PlaylistTrack.PlaylistId
GROUP BY Playlist.PlaylistId
4 changes: 4 additions & 0 deletions sales_agent_customer_count.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT Count(Customer.SupportRepId) AS NumberOfCustomers, Customer.SupportRepId, Employee.FirstName || " " || Employee.LastName AS FullName
FROM Employee
JOIN Customer ON Employee.EmployeeId == Customer.SupportRepId
GROUP BY Employee.FirstName
4 changes: 4 additions & 0 deletions sales_agent_invoices.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT Employee.FirstName, Employee.LastName, Invoice.*
FROM Employee
JOIN Customer ON Customer.SupportRepId == Employee.EmployeeId
JOIN Invoice ON Invoice.CustomerId == Customer.CustomerId
5 changes: 5 additions & 0 deletions sales_agent_total_sales.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT Employee.FirstName ||" "|| Employee.LastName AS "Employee Name" , SUM(Total) AS TotalSales
FROM Invoice
JOIN Employee ON Employee.EmployeeId = Customer.SupportRepId
JOIN Customer ON Customer.CustomerId = Invoice.CustomerId
GROUP BY Employee.FirstName
3 changes: 3 additions & 0 deletions sales_agents.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT *
FROM Employee
WHERE Title == "Sales Support Agent"
6 changes: 6 additions & 0 deletions sales_per_country.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT TotalSales, CountryName
FROM (SELECT Count(Invoice.BillingCountry) AS TotalSales, Invoice.BillingCountry AS CountryName
FROM Employee
JOIN Customer ON Employee.EmployeeId == Customer.SupportRepId
JOIN Invoice ON Customer.CustomerId == Invoice.CustomerId
GROUP BY CountryName)
7 changes: 7 additions & 0 deletions top_2009_agent.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SELECT MAX(Total), FullName
FROM (SELECT SUM(Invoice.Total) AS Total, Employee.FirstName || " " || Employee.LastName AS FullName, Customer.FirstName || " " || Employee.EmployeeId
FROM Employee
JOIN Customer ON Employee.EmployeeId == Customer.SupportRepId
JOIN Invoice ON Customer.CustomerId == Invoice.CustomerId
WHERE strftime('%Y',InvoiceDate) IN ('2009')
GROUP BY FullName)
9 changes: 9 additions & 0 deletions top_2013_track.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SELECT *
FROM (SELECT COUNT(Track.TrackId) AS TotalSales, Track.Name AS TrackName
FROM Invoice
JOIN InvoiceLine ON InvoiceLine.InvoiceId = Invoice.InvoiceId
JOIN Track ON InvoiceLine.TrackId = Track.TrackId
WHERE strftime('%Y',InvoiceDate) IN ('2013')
GROUP BY TrackName
ORDER BY TotalSales
LIMIT 1)
10 changes: 10 additions & 0 deletions top_3_artists.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SELECT *
FROM (SELECT COUNT(Album.ArtistId) AS TotalSales, Track.Name AS TrackName, Artist.Name AS ArtistName
FROM Album
JOIN Artist ON Artist.ArtistId = Album.ArtistId
JOIN Track ON Track.AlbumId = Album.AlbumId
JOIN Invoice ON Invoice.InvoiceId = InvoiceLine.InvoiceId
JOIN InvoiceLine ON Track.TrackId = InvoiceLine.TrackId
GROUP BY ArtistName)
ORDER BY TotalSales
DESC LIMIT 3
8 changes: 8 additions & 0 deletions top_5_tracks.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SELECT TrackName, TotalSales
FROM (SELECT COUNT(Invoice.InvoiceId) AS TotalSales, Track.Name AS TrackName
FROM Invoice
JOIN InvoiceLine ON InvoiceLine.InvoiceId = Invoice.InvoiceId
JOIN Track ON InvoiceLine.TrackId = Track.TrackId
GROUP BY TrackName)
ORDER BY TotalSales
DESC LIMIT 5
6 changes: 6 additions & 0 deletions top_agent.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT MAX(Total), FullName
FROM (SELECT SUM(Invoice.Total) AS Total, Employee.FirstName || " " || Employee.LastName AS FullName, Customer.FirstName || " " || Employee.EmployeeId
FROM Employee
JOIN Customer ON Employee.EmployeeId == Customer.SupportRepId
JOIN Invoice ON Customer.CustomerId == Invoice.CustomerId
GROUP BY FullName)
6 changes: 6 additions & 0 deletions top_country.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT MAX(TotalSales) , CountryName
FROM (SELECT MAX(Invoice.Total) AS TotalSales, Invoice.BillingCountry AS CountryName
FROM Employee
JOIN Customer ON Employee.EmployeeId == Customer.SupportRepId
JOIN Invoice ON Customer.CustomerId == Invoice.CustomerId
GROUP BY CountryName)
11 changes: 11 additions & 0 deletions top_media_type.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SELECT MediaName, TotalPlays
FROM (SELECT COUNT(Track.TrackId) AS TotalPlays, Track.Name AS TrackName, Artist.Name AS ArtistName, MediaType.Name AS MediaName
FROM Album
JOIN Artist ON Artist.ArtistId = Album.ArtistId
JOIN Track ON Track.AlbumId = Album.AlbumId
JOIN Invoice ON Invoice.InvoiceId = InvoiceLine.InvoiceId
JOIN InvoiceLine ON Track.TrackId = InvoiceLine.TrackId
JOIN MediaType ON MediaType.MediaTypeId = Track.MediaTypeId
GROUP BY MediaName)
ORDER BY TotalPlays
DESC LIMIT 1
3 changes: 3 additions & 0 deletions total_invoices_{year}.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT COUNT(*)
FROM Invoice
WHERE strftime('%Y',InvoiceDate) in ('2009', '2011')
3 changes: 3 additions & 0 deletions total_sales_{year}.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT Sum(Total)
FROM Invoice
WHERE strftime('%Y',InvoiceDate) in ('2009', '2011')
6 changes: 6 additions & 0 deletions tracks_no_id.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT Track.Name AS TrackName, MediaType.Name AS MediaName, Genre.Name AS GenreName
FROM Track
JOIN PlaylistTrack ON PlaylistTrack.TrackId = Track.TrackId
JOIN Playlist ON Playlist.PlaylistId = PlaylistTrack.PlaylistId
JOIN MediaType ON Track.MediaTypeId = MediaType.MediaTypeId
JOIN Genre ON Genre.GenreId = Track.GenreId
2 changes: 2 additions & 0 deletions unique_invoice_countries.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT DISTINCT BillingCountry
FROM Invoice