Git Product home page Git Product logo

sql-statements's Introduction

sql-statements

  1. Provide a query showing Customers (just their full names, customer ID and country) who are not in the US.

SELECT FirstName || " " || LastName, CustomerId, Country FROM Customer

WHERE Customer.Country != "USA";

  1. Provide a query only showing the Customers from Brazil.

SELECT FirstName || " " || LastName, CustomerId, Country FROM Customer

WHERE Customer.Country = "Brazil";

  1. 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 FirstName || ' ' || LastName AS "FullName", Customer.CustomerId, Customer.Country, Invoice.InvoiceId, Invoice.InvoiceDate, Invoice.BillingCountry FROM Customer

JOIN Invoice ON Customer.CustomerId = Invoice.CustomerId

WHERE Customer.Country = "Brazil";

  1. Provide a query showing only the Employees who are Sales Agents.

SELECT FirstName || ' ' || LastName AS "FullName" FROM Employee

WHERE Employee.Title = "Sales Support Agent";

  1. Provide a query showing a unique list of billing countries from the Invoice table.

SELECT BillingCountry FROM Invoice

GROUP BY BillingCountry

ORDER BY BillingCountry ASC;

  1. Provide a query showing the invoices of customers who are from Brazil.

SELECT FirstName || ' ' || LastName AS "FullName", Invoice.* FROM Customer

JOIN Invoice ON Customer.CustomerId = Invoice.CustomerId

  1. Provide a query that shows the invoices associated with each sales agent. The resultant table should include the Sales Agent's full name.

SELECT Employee.FirstName || ' ' || Employee.LastName AS "FullName", Invoice.* FROM Employee

JOIN Customer ON Employee.EmployeeId = Customer.SupportRepId

JOIN Invoice ON Customer.CustomerId = Invoice.CustomerId

WHERE Employee.Title = "Sales Support Agent"

  1. Provide a query that shows the Invoice Total, Customer name, Country and Sale Agent name for all invoices and customers.

SELECT Invoice.Total, Invoice.BillingCountry, Customer.FirstName || ' ' || Customer.LastName AS "CustomerName", Employee.FirstName || ' ' || Employee.LastName AS "SalesAgent" FROM Invoice, Customer

JOIN Employee ON Customer.SupportRepId = EmployeeId

  1. How many Invoices were there in 2009 and 2011? What are the respective total sales for each of those years?

a. SELECT sum(Invoice.Total), Invoice.InvoiceDate FROM Invoice WHERE Invoice.InvoiceDate < '2010-01-01 00:00:00'

##83

b.

SELECT sum(Invoice.Total), Invoice.InvoiceDate FROM Invoice WHERE Invoice.InvoiceDate > '2011-01-01 00:00:00' AND Invoice.InvoiceDate > '2012-01-01 00:00:00'

##163

  1. Looking at the InvoiceLine table, provide a query that COUNTs the number of line items for Invoice ID 37.

SELECT InvoiceLine.InvoiceId, sum(InvoiceLine.Quantity) AS "Total Items" from InvoiceLine

WHERE InvoiceLine.InvoiceId = 37

  1. Looking at the InvoiceLine table, provide a query that COUNTs the number of line items for each Invoice. HINT: GROUP BY

SELECT InvoiceLine.InvoiceId, sum(InvoiceLine.Quantity) AS "Total Items" from InvoiceLine

GROUP BY InvoiceLine.InvoiceId

  1. Provide a query that includes the track name with each invoice line item.

SELECT InvoiceLine.InvoiceLineId, Track.Name from InvoiceLine, Track

  1. Provide a query that includes the purchased track name AND artist name with each invoice line item.

SELECT InvoiceLine.InvoiceLineId, Track.Name, Artist.Name from InvoiceLine, Track

JOIN Album ON Track.AlbumId = Album.AlbumId

JOIN Artist ON Album.ArtistId = Artist.ArtistId

  1. Provide a query that shows the # of invoices per country. HINT: GROUP BY

SELECT COUNT(Invoice.BillingCountry) AS "Total Invoices", Invoice.BillingCountry FROM Invoice

GROUP BY(Invoice.BillingCountry)

  1. Provide a query that shows the total number of tracks in each playlist. The Playlist name should be include on the resultant table.

  2. Provide a query that shows all the Tracks, but displays no IDs. The resultant table should include the Album name, Media type and Genre.

  3. Provide a query that shows all Invoices but includes the # of invoice line items.

  4. Provide a query that shows total sales made by each sales agent.

  5. Which sales agent made the most in sales in 2009?

  6. Which sales agent made the most in sales in 2010?

  7. Which sales agent made the most in sales over all?

  8. Provide a query that shows the # of customers assigned to each sales agent.

  9. Provide a query that shows the total sales per country. Which country's customers spent the most?

  10. Provide a query that shows the most purchased track of 2013.

  11. Provide a query that shows the top 5 most purchased tracks over all.

  12. Provide a query that shows the top 3 best selling artists.

  13. Provide a query that shows the most purchased Media Type.

sql-statements's People

Contributors

danrday avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.