123456789101112131415161718192021222324252627 |
- SELECT 'Active' AS source, invoice_number, invoice_date, invoice_total
- FROM invoices
- WHERE invoice_total - payment_total - credit_total > 0
- UNION
- SELECT 'Paid' AS source, invoice_number, invoice_date, invoice_total
- FROM invoices
- WHERE invoice_total - payment_total - credit_total <= 0
- ORDER BY invoice_total DESC;
-
- SELECT invoice_number, vendor_name, '33% Payment' AS payment_type,
- invoice_total AS total, invoice_total * 0.333 AS payment
- FROM invoices JOIN vendors
- ON invoices.vendor_id = vendors.vendor_id
- WHERE invoice_total > 10000
- UNION
- SELECT invoice_number, vendor_name, '50% Payment' AS payment_type,
- invoice_total AS total, invoice_total * 0.5 AS payment
- FROM invoices JOIN vendors
- ON invoices.vendor_id = vendors.vendor_id
- WHERE invoice_total BETWEEN 500 AND 10000
- UNION
- SELECT invoice_number, vendor_name, 'Full amount' AS payment_type,
- invoice_total AS total, invoice_total AS payment
- FROM invoices JOIN vendors
- ON invoices.vendor_id = vendors.vendor_id
- WHERE invoice_total < 500
- ORDER BY payment_type, vendor_name, invoice_number;
|