Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aggregate function and other columns

Tags:

sql

aggregate

Is it possible for a SQL query to return some normal columns and some aggregate ones?

like :

Col_A | Col_B | SUM
------+-------+------
   5  |   6   |  7
like image 656
zz1433 Avatar asked Feb 26 '26 04:02

zz1433


1 Answers

You should use the group by statement.

The GROUP BY statement is used in conjunction with the aggregate functions to group the result-set by one or more columns.

For example:

SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name

You can see a complete example here.

like image 146
eKek0 Avatar answered Feb 28 '26 17:02

eKek0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!