@@ -1,4 +1,4 @@ | |||
SELECT vendor_id, | |||
sum(invoice_total) AS invoice_total_sum | |||
SUM(invoice_total) AS invoice_total_sum | |||
FROM invoices | |||
GROUP BY vendor_id; |
@@ -1,6 +1,6 @@ | |||
SELECT v.vendor_name, | |||
SUM(i.payment_total) AS payment_total_sum | |||
FROM vendors v JOIN invoices i | |||
WHERE v.vendor_id = i.vendor_id | |||
ON v.vendor_id = i.vendor_id | |||
GROUP BY v.vendor_name | |||
ORDER BY payment_total_sum DESC; |
@@ -3,6 +3,6 @@ SELECT | |||
COUNT(*) AS number_of_invoices, | |||
SUM(i.invoice_total) AS invoice_total_sum | |||
FROM vendors v JOIN invoices i | |||
WHERE v.vendor_id = i.vendor_id | |||
ON v.vendor_id = i.vendor_id | |||
GROUP BY v.vendor_name | |||
ORDER BY number_of_invoices DESC; |
@@ -3,7 +3,7 @@ SELECT DISTINCT | |||
COUNT(line_item_amount) AS line_item_amount_count, | |||
SUM(i.line_item_amount) AS line_item_amount_sum | |||
FROM general_ledger_accounts g JOIN invoice_line_items i | |||
WHERE g.account_number = i.account_number | |||
ON g.account_number = i.account_number | |||
GROUP BY g.account_description | |||
HAVING line_item_amount_count > 1 | |||
ORDER BY line_item_amount_sum DESC; |
@@ -4,7 +4,7 @@ SELECT DISTINCT | |||
SUM(i.line_item_amount) AS line_item_amount_sum, | |||
n.invoice_date | |||
FROM general_ledger_accounts g JOIN invoice_line_items i JOIN invoices n | |||
WHERE g.account_number = i.account_number AND i.invoice_id = n.invoice_id | |||
ON g.account_number = i.account_number AND i.invoice_id = n.invoice_id | |||
GROUP BY g.account_description | |||
HAVING n.invoice_date >= '2018-04-01' AND n.invoice_date <= '2018-06-30' | |||
ORDER BY line_item_amount_sum DESC; |
@@ -2,5 +2,5 @@ SELECT | |||
i.account_number, | |||
SUM(i.line_item_amount) AS line_items_amount_sum | |||
FROM invoice_line_items i JOIN general_ledger_accounts g | |||
WHERE i.account_number = g.account_number | |||
ON i.account_number = g.account_number | |||
GROUP BY i.account_number WITH ROLLUP; |
@@ -2,6 +2,6 @@ SELECT | |||
v.vendor_name, | |||
COUNT(DISTINCT g.account_number) AS distinct_accounts | |||
FROM vendors v JOIN general_ledger_accounts g JOIN invoice_line_items i JOIN invoices n | |||
WHERE v.vendor_id = n.vendor_id AND i.invoice_id = n.invoice_id AND i.account_number = g.account_number | |||
ON v.vendor_id = n.vendor_id AND i.invoice_id = n.invoice_id AND i.account_number = g.account_number | |||
GROUP BY v.vendor_name | |||
HAVING distinct_accounts > 1; |