SQ L Group by Claushie

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

8/10/13

SQL Group By Clause

SQL GROUP BY Clause


The SQL GROUP BY C lause is used along with the group functions to retrieve data grouped according to one or
more columns.
For Example: If you want to know the total amount of salary spent on each department, the query would be:

SELECT dept, SUM (salary)


FROM employee
GROUP BY dept;
The output would be like:

dept
salary
------------- --------------Electrical
25000
Electronics 55000
Aeronautics 35000
InfoTech
30000
NOTE: The group by clause should contain all the columns in the select list expect those used along with the
group functions.

SELECT location, dept, SUM (salary)


FROM employee
GROUP BY location, dept;
The output would be like:

location
dept
salary
------------ ------------- ----------Bangalore Electrical
25000
Bangalore Electronics 55000
Mysore
Aeronautics 35000
Mangalore InfoTech
30000

beginner-sql-tutorial.com/sql-group-by-clause.htm

1/1

You might also like