You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

demo-queries-from slides-14.sql 1.1KB

123456789101112131415161718192021222324252627
  1. SELECT 'Active' AS source, invoice_number, invoice_date, invoice_total
  2. FROM invoices
  3. WHERE invoice_total - payment_total - credit_total > 0
  4. UNION
  5. SELECT 'Paid' AS source, invoice_number, invoice_date, invoice_total
  6. FROM invoices
  7. WHERE invoice_total - payment_total - credit_total <= 0
  8. ORDER BY invoice_total DESC;
  9. SELECT invoice_number, vendor_name, '33% Payment' AS payment_type,
  10. invoice_total AS total, invoice_total * 0.333 AS payment
  11. FROM invoices JOIN vendors
  12. ON invoices.vendor_id = vendors.vendor_id
  13. WHERE invoice_total > 10000
  14. UNION
  15. SELECT invoice_number, vendor_name, '50% Payment' AS payment_type,
  16. invoice_total AS total, invoice_total * 0.5 AS payment
  17. FROM invoices JOIN vendors
  18. ON invoices.vendor_id = vendors.vendor_id
  19. WHERE invoice_total BETWEEN 500 AND 10000
  20. UNION
  21. SELECT invoice_number, vendor_name, 'Full amount' AS payment_type,
  22. invoice_total AS total, invoice_total AS payment
  23. FROM invoices JOIN vendors
  24. ON invoices.vendor_id = vendors.vendor_id
  25. WHERE invoice_total < 500
  26. ORDER BY payment_type, vendor_name, invoice_number;