# Summarizing Data - Aggregate Functions exercise

**URL:** <https://forum.codewithmosh.com/t/summarizing-data-aggregate-functions-exercise/24482>\
**Category:** SQL\
**Created:** [January 8, 2024, 2:12am UTC](https://forum.codewithmosh.com/t/summarizing-data-aggregate-functions-exercise/24482 "2024-01-08T02:12:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andresturriago](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@andresturriago](https://forum.codewithmosh.com/u/andresturriago)\
**Post date:** [January 8, 2024, 2:12am UTC](https://forum.codewithmosh.com/t/summarizing-data-aggregate-functions-exercise/24482/1 "2024-01-08T02:12:10Z")

</div>

Hi,

Can please someone explain to me why I’m getting this different output for this exercise?  
I restored the databases just like the previous video class indicates.  
The query that I run is the solution of Mosh

Mosh query output

| date\_range | total\_sales | total\_payments | what\_we\_expect |
| --- | --- | --- | --- |
| First half of 2019 | 1539.07 | 662.69 | 876.38 |
| Second half of 2019 | 1051.53 | 355.02 | 696.51 |
| Total | 2590.60 | 1017.71 | 1572.89 |

My output

 ![Screenshot 2024-01-07 203603](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/6/6eb80f38643a8a72d20e7c876fce6ffc987e91ab.png)

The query that I run is the solution of Mosh

```sql
-- USE sql_invoicing;
SELECT 
    'First half of 2019' AS date_range,
    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 date_range,
    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-31'
UNION
SELECT 
    'Total' AS date_range,
    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-12-31'

```

Thanks,

---

<div class="post-metadata">

**Author:** ![blitzmacht](https://avatars.discourse-cdn.com/v4/letter/b/e95f7d/32.png) [@blitzmacht](https://forum.codewithmosh.com/u/blitzmacht)\
**Post date:** [January 8, 2024, 11:53pm UTC](https://forum.codewithmosh.com/t/summarizing-data-aggregate-functions-exercise/24482/2 "2024-01-08T23:53:29Z")

</div>

> [@andresturriago](#):
>
> ```auto
> -- USE sql_invoicing;
> SELECT 
> 'First half of 2019' AS date_range,
> 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 date_range,
> 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-31'
> UNION
> SELECT 
> 'Total' AS date_range,
> 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-12-31'
> 
> ```

I get the same results as you. Did the total\_payments on calculator to confirm the results. My guess is they changed the script that creates the invoices table using different data than when the video was recorded.

---

<div class="post-metadata">

**Author:** ![andresturriago](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@andresturriago](https://forum.codewithmosh.com/u/andresturriago)\
**Post date:** [January 9, 2024, 4:40am UTC](https://forum.codewithmosh.com/t/summarizing-data-aggregate-functions-exercise/24482/3 "2024-01-09T04:40:47Z")

</div>

Hi @blitzmacht,

I think your guess is probably right.

Thanks for your help 👍
