Aggregate function and other columns

Is it possible for an SQL query to return some normal columns and some aggregated ones?

like:

Col_A | Col_B | SUM
------+-------+------
   5  |   6   |  7
+3
source share
5 answers

You can use group by statement .

The GROUP BY clause is used in conjunction with a collection of functions to group the result of 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

Here you can see the full example here .

+7
source

Oh sure. Read about GROUP BY and aggregate functions. eg.

SELECT col1, col2, SUM(col3) 
FROM table 
GROUP BY col1, col2
+1
source

, GROUP BY.

0

GROUP BY , ; :.

SELECT colA, colB, SUM(colC)
FROM TheTable
GROUP BY colA, colB

aggregation can be performed using SUM, MIN, MAX, etc.

0
source

You can display regular columns or expressions based on regular columns, but only if they are included in the set of columns / expressions that you are aggregating (as indicated in the Group By clause).

0
source

Source: https://habr.com/ru/post/1714671/


All Articles