# Aggregate function

**URL:** <https://forum.codewithmosh.com/t/aggregate-function/20556>\
**Category:** Uncategorized\
**Created:** [May 30, 2023, 10:22pm UTC](https://forum.codewithmosh.com/t/aggregate-function/20556 "2023-05-30T22:22:11Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ethan](https://avatars.discourse-cdn.com/v4/letter/e/8dc957/32.png) [@ethan](https://forum.codewithmosh.com/u/ethan)\
**Post date:** [May 30, 2023, 10:22pm UTC](https://forum.codewithmosh.com/t/aggregate-function/20556/1 "2023-05-30T22:22:11Z")

</div>

I am in the aggregates lecture, and all of the aggregate functions are not working; I mean, they don’t turn blue.  
please help

 ![Capture](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/5/5f91378de834536040f68d4307a10f3aa6214f31.png)

---

<div class="post-metadata">

**Author:** ![SAM](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/sam/32/167_2.png) [@SAM](https://forum.codewithmosh.com/u/SAM)\
**Post date:** [May 31, 2023, 4:36am UTC](https://forum.codewithmosh.com/t/aggregate-function/20556/2 "2023-05-31T04:36:42Z")

</div>

You have a space between `SUM` and `(` .

---

<div class="post-metadata">

**Author:** ![ethan](https://avatars.discourse-cdn.com/v4/letter/e/8dc957/32.png) [@ethan](https://forum.codewithmosh.com/u/ethan)\
**Post date:** [May 31, 2023, 11:17am UTC](https://forum.codewithmosh.com/t/aggregate-function/20556/3 "2023-05-31T11:17:18Z")

</div>

it worked but i still got an error message, though it still didn’t get highlighted in blue like in the tutorial videos. thanks anyway.

---

<div class="post-metadata">

**Author:** ![lucidlear](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/lucidlear/32/5477_2.png) [@lucidlear](https://forum.codewithmosh.com/u/lucidlear)\
**Post date:** [May 31, 2023, 11:30am UTC](https://forum.codewithmosh.com/t/aggregate-function/20556/4 "2023-05-31T11:30:58Z")

</div>

Hi, you have the wrong column name it is ‘invoice\_total’ not ‘invoicing\_total’ in the invoices table.

Also sum is not blue for me, its purple because its function it shows differently, I think because Mosh was on older version of MySQL Workbench thats why he was blue

---

<div class="post-metadata">

**Author:** ![ethan](https://avatars.discourse-cdn.com/v4/letter/e/8dc957/32.png) [@ethan](https://forum.codewithmosh.com/u/ethan)\
**Post date:** [May 31, 2023, 11:35am UTC](https://forum.codewithmosh.com/t/aggregate-function/20556/5 "2023-05-31T11:35:47Z")

</div>

worked just fine; mine is actually light gray.  
thanks a lot.

---

<div class="post-metadata">

**Author:** ![Mritunjayanup](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@Mritunjayanup](https://forum.codewithmosh.com/u/Mritunjayanup)\
**Post date:** [June 20, 2023, 5:20am UTC](https://forum.codewithmosh.com/t/aggregate-function/20556/6 "2023-06-20T05:20:37Z")

</div>

Hi everyone!

I am on the aggregate function lecture and I am writing the following code :-  
SELECT  
p.date,  
SUM(p.amount) AS total\_payments,  
pm.name as payment\_method  
FROM payments p  
JOIN payment\_methods pm  
ON p.payment\_id = pm.payment\_method\_id  
GROUP BY p.date;

I am getting an error :Error code 1055. Select list is not in GROUP BY clause. Mosh entered the same code and his worked

---

<div class="post-metadata">

**Author:** ![SAM](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/sam/32/167_2.png) [@SAM](https://forum.codewithmosh.com/u/SAM)\
**Post date:** [June 20, 2023, 6:44am UTC](https://forum.codewithmosh.com/t/aggregate-function/20556/7 "2023-06-20T06:44:08Z")

</div>

Mosh groups by `date` and `payment_method` .

---

<div class="post-metadata">

**Author:** ![Mritunjayanup](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@Mritunjayanup](https://forum.codewithmosh.com/u/Mritunjayanup)\
**Post date:** [June 20, 2023, 6:56am UTC](https://forum.codewithmosh.com/t/aggregate-function/20556/8 "2023-06-20T06:56:19Z")

</div>

@SAM Thank you for your response. Can you please help me understand why my code could be getting an error?

Thank you in advance

---

<div class="post-metadata">

**Author:** ![SAM](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/sam/32/167_2.png) [@SAM](https://forum.codewithmosh.com/u/SAM)\
**Post date:** [June 20, 2023, 7:15am UTC](https://forum.codewithmosh.com/t/aggregate-function/20556/9 "2023-06-20T07:15:32Z")

</div>

All `SELECT`ed columns that are not aggregates should be `GROUP`ed. That’s what the error message says.

If you have multiple `payment_method`s used on a `date` and group by `date` only - which `payment_method` value should the database return? Either would be wrong since the `SUM` includes them all.
