Skip to content
Open
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
29 changes: 29 additions & 0 deletions examples/example_queries.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
SELECT
c.CustomerId,
c.FirstName,
c.LastName,
SUM(i.Total) AS TotalSpent
FROM Customers c
JOIN Invoices i ON c.CustomerId = i.CustomerId
GROUP BY c.CustomerId, c.FirstName, c.LastName
ORDER BY TotalSpent DESC;


-- Find albums with more than 10 tracks
SELECT
a.AlbumId,
a.Title,
COUNT(t.TrackId) AS TrackCount
FROM Albums a
JOIN Tracks t ON a.AlbumId = t.AlbumId
GROUP BY a.AlbumId, a.Title
HAVING COUNT(t.TrackId) > 10;

-- Customers who never made a purchase
SELECT
c.CustomerId,
c.FirstName,
c.LastName
FROM Customers c
LEFT JOIN Invoices i ON c.CustomerId = i.CustomerId
WHERE i.InvoiceId IS NULL;