I’m getting different results on the summarizing data/aggregate functions exercise and my code is the same as mosh’s, here is my code:
@Mosh
SELECT
'First half of 2019' AS range_date,
SUM(invoice_total) AS total_sales,
SUM(payment_total) AS total_payments,
SUM(invoice_total - 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 range_date,
SUM(invoice_total) AS total_sales,
SUM(payment_total) AS total_payments,
SUM(invoice_total - payment_total) AS what_we_expect
FROM invoices
WHERE invoice_date BETWEEN '2019-07-01' AND '2019-12-30'
UNION
SELECT
'total' AS range_date,
SUM(invoice_total) AS total_sales,
SUM(payment_total) AS total_payments,
SUM(invoice_total - payment_total) AS what_we_expect
FROM invoices
WHERE invoice_date
BETWEEN '2019-01-01' AND '2019-06-30'
HERE ARE MY RESULTS
| range_date | total_sales | total_payments | what_we_expect |
|-----------------------|-------------|----------------|----------------|
| total | 1539.07 | 212.97 | 1326.10 |
| Second Half of 2019 | 1051.53 | 148.41 | 903.12 |
| First half of 2019 | 1539.07 | 212.97 | 1326.10 |