Doing the first exercise in the SQL Aggregating Functions video. My code is practically the same as Mosh’s but i’m getting different results for the sum of payments (sum of sales is the same). After inspecting the invoices table it appears that my code is working correctly but Mosh must be using a more complete version of the invoices table with either more rows and/or more complete payments info (my column is mostly zero’s).
Should I continue and not worry about this? Or have I missed something?
----------------------------------------CODE -------------------------------------------
USE sql_invoicing;
SELECT
“First half of 2019” AS Time_Period,
SUM(invoice_total) AS Total_Sales,
SUM(payment_toinvoicestal) AS Total_Payments,
SUM(invoice_total) - SUM(payment_total) AS What_we_expect
FROM invoices
WHERE invoice_date BETWEEN ‘2019-01-01’ AND ‘2019-06-30’
UNION
SELECT
“Second half of 2019” AS Time_Period,
SUM(invoice_total) AS Total_Sales,
SUM(payment_total) AS Total_Payments,
SUM(invoice_total) - SUM(payment_total) AS What_we_expect
FROM invoices
WHERE invoice_date BETWEEN ‘2019-07-01’ AND ‘2019-12-31’
UNION
SELECT
“Total” AS Time_Period,
SUM(invoice_total) AS Total_Sales,
SUM(payment_total) AS Total_Payments,
SUM(invoice_total) - SUM(payment_total) AS What_we_expect
FROM invoices
WHERE invoice_date BETWEEN ‘2019-01-01’ AND ‘2019-12-31’