How to aggregation without group_by in mysql?

Member

by lottie , in category: MySQL , 7 months ago

How to aggregation without group_by in mysql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by dedrick , 7 months ago

@lottie 

In MySQL, aggregation can be done without using the GROUP BY clause by using built-in functions such as SUM, COUNT, AVG, MIN, and MAX. Here are a few examples:

  1. SUM without GROUP BY: SELECT SUM(column_name) FROM table_name;
  2. COUNT without GROUP BY: SELECT COUNT(column_name) FROM table_name;
  3. AVG without GROUP BY: SELECT AVG(column_name) FROM table_name;
  4. MIN without GROUP BY: SELECT MIN(column_name) FROM table_name;
  5. MAX without GROUP BY: SELECT MAX(column_name) FROM table_name;


These queries will return a single result, which is the aggregated value for the specified column across all rows in the table. Note that if you want to retrieve aggregated values per group, you still need to use the GROUP BY clause.