compsci-notes-spring-2024/notes/database-prog/sql-scripts/2024-01-31.sql

34 lines
1.3 KiB
MySQL
Raw Normal View History

2024-01-31 20:20:15 -06:00
-- #### Start of class stuff ####
2024-01-31 20:43:31 -06:00
-- Get the InvoiceID, InvoiceTotal, and InvoiceDueDate for all invoices for vendor 110
SELECT InvoiceID, InvoiceTotal, InvoiceDueDate
2024-01-31 20:20:15 -06:00
FROM Invoices
WHERE VendorID = 110
2024-01-31 20:43:31 -06:00
-- Get the latest 10 invoices for vendor 123: InvoiceID, InvoiceDueDate, InvoiceTotal
SELECT TOP 10 InvoiceID, InvoiceTotal, InvoiceDueDate
2024-01-31 20:20:15 -06:00
FROM Invoices
WHERE VendorID = 123
ORDER BY InvoiceDueDate DESC
2024-01-31 20:43:31 -06:00
-- Get the InvoiceID, VendorID, InvoiceDueDate, and InvoiceTotal for all invoices due between 1/1/2020 and 1/31/2020
SELECT InvoiceID, VendorID, InvoiceDueDate, InvoiceTotal
2024-01-31 20:20:15 -06:00
FROM Invoices
WHERE InvoiceDueDate BETWEEN '1/1/2020' AND '1/31/2020'
2024-01-31 20:43:31 -06:00
-- ######################################################################## --
-- Get top 10 unpaid invoices
SELECT TOP 10 InvoiceID, VendorID, InvoiceTotal, InvoiceDueDate FROM Invoices
WHERE PaymentDate IS NULL
ORDER BY InvoiceDueDate
SELECT VendorID, VendorName, VendorContactLName, VendorContactFName FROM Vendors
WHERE VendorID IN (72, 83, 80, 123, 110, 106, 37) -- Output from last query
-- Combine them with JOIN
SELECT TOP 10 InvoiceID, Invoices.VendorID, InvoiceTotal, InvoiceDueDate, VendorName, VendorContactLName, VendorContactFName
FROM Invoices
JOIN Vendors ON Invoices.VendorID = Vendors.VendorID
WHERE PaymentDate IS NULL
ORDER BY InvoiceDueDate