1 Star 0 Fork 1

MicroGateGroup/chinook_system

forked from DaviesGit/chinook_system 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
answer.sql 6.53 KB
一键复制 编辑 原始数据 按行查看 历史
Davies 提交于 2020-09-26 23:07 . Project migration
SELECT FirstName || " " || LastName AS Name, CustomerId, Country FROM Customer WHERE Country <> "USA";
SELECT * FROM Customer WHERE Country IS "Brazil";
SELECT c.FirstName || " " || c.LastName as Name, i.InvoiceId, i.InvoiceDate, c.Country FROM Customer c LEFT JOIN Invoice i ON i.CustomerId = c.CustomerId WHERE c.Country IS "Brazil";
SELECT * FROM Employee WHERE Title LIKE "%Sale%Agent%";
SELECT BillingCountry FROM Invoice GROUP BY BillingCountry;
SELECT i.InvoiceId, (e.FirstName || " " || e.LastName) as Name FROM Invoice i LEFT JOIN Customer c ON c.CustomerId = i.CustomerId LEFT JOIN Employee e ON c.SupportRepId = e.EmployeeId;
SELECT (c.FirstName || " " || c.LastName) as CustomerName, (e.FirstName || " " || e.LastName) as SalesAgentName, i.Total, i.BillingCountry FROM Invoice i LEFT JOIN Customer c ON c.CustomerId = i.CustomerId LEFT JOIN Employee e ON c.SupportRepId = e.EmployeeId;
SELECT (SELECT COUNT(*) FROM Invoice i WHERE SUBSTR(i.InvoiceDate,0,5) = "2009") AS Invoices09, (SELECT COUNT(*) FROM Invoice i WHERE SUBSTR(i.InvoiceDate,0,5) = "2011") AS Invoices11;
SELECT COUNT(*) FROM InvoiceLine il WHERE il.InvoiceId = 37;
SELECT InvoiceId, COUNT(*) FROM InvoiceLine il GROUP BY InvoiceId;
SELECT t.Name, il.* FROM InvoiceLine il LEFT JOIN Track t ON t.TrackId = il.TrackId;
SELECT t.Name as Song, ar.Name AS Artist, il.* FROM InvoiceLine il LEFT JOIN Track t ON t.TrackId = il.TrackId LEFT JOIN Album al ON al.AlbumId = t.AlbumId LEFT JOIN Artist ar ON ar.ArtistId = al.ArtistId;
SELECT Invoice.BillingCountry, COUNT(*) FROM Invoice GROUP BY BillingCountry;
SELECT p.Name, COUNT(*) FROM Playlist p LEFT JOIN PlaylistTrack pt ON pt.PlaylistId = p.PlaylistId GROUP BY pt.PlaylistId;
SELECT t.Name AS Song, a.Title as Album, mt.Name AS MediaType, g.Name AS Genre FROM Track t LEFT JOIN MediaType mt on mt.MediaTypeId = t.MediaTypeId LEFT JOIN Album a ON a.AlbumId = t.AlbumId LEFT JOIN Genre g ON g.GenreId = t.GenreId;
SELECT i.*, COUNT(*) as LineCount FROM Invoice i LEFT JOIN InvoiceLine il ON i.InvoiceId = il.InvoiceId GROUP BY i.InvoiceId;
SELECT e.FirstName || " " || e.lastName as Name, COUNT(*) AS Sales FROM Employee e JOIN Customer c ON c.SupportRepId = e.EmployeeId JOIN Invoice i ON i.CustomerId = c.CustomerId GROUP BY EmployeeId;
SELECT e.FirstName || " " || e.lastName as Name, COUNT(*) AS Sales FROM Employee e JOIN Customer c ON c.SupportRepId = e.EmployeeId JOIN Invoice i ON i.CustomerId = c.CustomerId WHERE SUBSTR(i.InvoiceDate,0,5) = "2009" GROUP BY EmployeeId ORDER BY Sales DESC;
SELECT e.FirstName || " " || e.lastName as Name, COUNT(*) AS Sales FROM Employee e JOIN Customer c ON c.SupportRepId = e.EmployeeId JOIN Invoice i ON i.CustomerId = c.CustomerId WHERE SUBSTR(i.InvoiceDate,0,5) = "2010" GROUP BY EmployeeId ORDER BY Sales DESC;
SELECT e.FirstName || " " || e.lastName as Name, COUNT(*) AS Sales FROM Employee e JOIN Customer c ON c.SupportRepId = e.EmployeeId JOIN Invoice i ON i.CustomerId = c.CustomerId GROUP BY EmployeeId ORDER BY Sales DESC;
SELECT e.EmployeeId, e.FirstName || " " || e.LastName as Employee, COUNT(*) FROM Customer c JOIN Employee e ON e.EmployeeId = c.SupportRepId GROUP BY e.EmployeeId;
SELECT BillingCountry, SUM(Total) FROM Invoice GROUP BY BillingCountry ORDER BY SUM(Total) DESC;
SELECT t.TrackId, COUNT(*) FROM InvoiceLine il JOIN Track t ON t.TrackId = il.TrackId JOIN Invoice i ON i.InvoiceId = il.InvoiceId WHERE SUBSTR(i.InvoiceDate,0,5) = "2013" GROUP BY il.TrackId ORDER BY COUNT(*) DESC;
SELECT t.TrackId, COUNT(*) FROM InvoiceLine il JOIN Track t ON t.TrackId = il.TrackId GROUP BY il.TrackId ORDER BY COUNT(*) DESC;
SELECT ar.Name, COUNT(*) FROM InvoiceLine il LEFT JOIN Track t ON t.TrackId = il.TrackId LEFT JOIN Album al ON al.AlbumId = t.AlbumId LEFT JOIN Artist ar ON ar.ArtistId = al.ArtistId GROUP BY ar.ArtistId ORDER BY COUNT(*) DESC LIMIT 3;
SELECT mt.Name, COUNT(*) FROM InvoiceLine il LEFT JOIN Track t ON t.TrackId = il.TrackId LEFT JOIN MediaType mt ON mt.MediaTypeId = t.MediaTypeId GROUP BY t.MediaTypeId ORDER BY COUNT(*) DESC;
SELECT BillingCountry AS billingCountry, COUNT(*) AS Invoices FROM Invoice GROUP BY BillingCountry ORDER BY Invoices DESC;
SELECT BillingCity AS billingCity, SUM(Total) AS InvoiceDollars FROM Invoice GROUP BY BillingCity ORDER BY InvoiceDollars DESC;
SELECT CustomerId AS customerId, SUM(Total) AS money_spent FROM Invoice GROUP BY CustomerId ORDER BY money_spent DESC LIMIT 1;
SELECT DISTINCT C.Email AS email, C.FirstName AS firstName, C.LastName AS lastName, G.Name AS name FROM Customer C JOIN Invoice I ON C.CustomerId = I.CustomerId JOIN InvoiceLine IL ON I.InvoiceId = IL.InvoiceId JOIN Track T ON IL.TrackId = T.TrackId JOIN Genre G ON T.GenreId = G.GenreId WHERE G.Name = 'Rock' ORDER BY C.Email;
SELECT Artist.ArtistId AS artistId, Artist.Name AS name, COUNT(Track.Name) AS Songs FROM Artist JOIN Album ON Album.ArtistId = Artist.ArtistId JOIN Track ON Album.AlbumId = Track.AlbumId JOIN Genre ON Track.GenreId = Genre.GenreId WHERE Genre.Name = 'Rock' GROUP BY Artist.ArtistId, Artist.Name, Genre.Name ORDER BY Songs DESC LIMIT 10;
SELECT a.Name AS name, SUM(il.Quantity * il.UnitPrice) AS AmountSpent, c.CustomerId AS customerId, c.FirstName AS firstName, c.LastName AS lastName FROM Artist a JOIN Album al ON a.ArtistId = al.ArtistId JOIN Track t ON t.AlbumId = al.AlbumId JOIN InvoiceLine il ON t.TrackId = il.Trackid JOIN Invoice i ON il.InvoiceId = i.InvoiceId JOIN Customer c ON c.CustomerId = i.CustomerId WHERE a.Name = 'Iron Maiden'GROUP BY c.CustomerId ORDER BY AmountSpent DESC;
WITH t1 AS ( SELECT COUNT(i.InvoiceId) Purchases, c.Country, g.Name, g.GenreId FROM Invoice i JOIN Customer c ON i.CustomerId = c.CustomerId JOIN InvoiceLine il ON il.Invoiceid = i.InvoiceId JOIN Track t ON t.TrackId = il.Trackid JOIN Genre g ON t.GenreId = g.GenreId GROUP BY c.Country, g.Name ORDER BY c.Country, Purchases DESC ) SELECT t1.* FROM t1 JOIN ( SELECT MAX(Purchases) AS MaxPurchases, Country, Name, GenreId FROM t1 GROUP BY Country )t2 ON t1.Country = t2.Country WHERE t1.Purchases = t2.MaxPurchases;
SELECT Name, Milliseconds FROM (SELECT t.Name, t.Milliseconds, (SELECT AVG(Milliseconds) FROM Track) AS AvgLenght FROM Track t WHERE AvgLenght < t.Milliseconds ORDER BY t.Milliseconds DESC );
WITH t1 AS ( SELECT c.Country, SUM(i.Total) TotalSpent, c.FirstName, c.LastName, c.CustomerId FROM Customer c JOIN Invoice i ON c.CustomerId = i.CustomerId GROUP BY c.CustomerId ) SELECT t1.* FROM t1 JOIN( SELECT Country, MAX(TotalSpent) AS MaxTotalSpent, FirstName, LastName, CustomerId FROM t1 GROUP BY Country )t2 ON t1.Country = t2.Country WHERE t1.TotalSpent = t2.MaxTotalSpent ORDER BY Country;
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/itmgg/chinook_system.git
git@gitee.com:itmgg/chinook_system.git
itmgg
chinook_system
chinook_system
master

搜索帮助