MySQL Forums
Forum List  »  MySQL Workbench

Re: GROUP BY is Broken?
Posted by: Peter Brawley
Date: February 19, 2022 09:59AM

Your query ...

select *
from test_table
group by BU,BU_Name,Product,Region,Year,Month;

... has a Group By clause, but calls no aggregating function. What were you hoping to accomplish with this query?

Group By is designed to return exactly one row per unique result of the Group By clause, and is intended to be used with functions which aggregate on such groupings (https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html), for example

select a, sum(b)
from t
group by a;

Consider reading the manual about Group By ...

https://www.mysqltutorial.org/mysql-group-by.aspx

https://dev.mysql.com/doc/refman/8.0/en/group-by-handling.html



Edited 1 time(s). Last edit at 02/19/2022 10:24AM by Peter Brawley.

Options: ReplyQuote


Subject
Views
Written By
Posted
390
February 19, 2022 09:05AM
259
February 19, 2022 09:07AM
Re: GROUP BY is Broken?
289
February 19, 2022 09:59AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.