Group By

NASRIN BAWANE
AI Perceptron
Published in
Nov 28, 2020

Group by works with aggregate functions like sum(),count() etc.

Group By give output in a group with one or more columns.

In group by, the column which is used for grouping is also be used in select statement that is both the column should be same in select and group by statement otherwise it will give error.

Syntax:

select column1,…..

from tablename

group by column1,…..

Sample Input:

Queries:

Query 1:

select count(*),depid
from emp
group by depid;

Output:

Query 2:

select min(salary),dept_name
from emp
group by dept_name;

Output:

Query 3:

select avg(age),depid
from emp
group by depid;

Output:

--

--