Labels

Wednesday, 23 December 2015

SQL Server - Group By Clause

Group By Clause 

Used to group similar values existing in the column of the table
It should be second clause i.e you have to use this clause after where clause only

Group By clause Rule

If you specify other than group function columns after select statement those columns must use after group by function otherwise SQL Server violates an error such as not a group by expression .

Recommendations

 Whenever we are using group by clause in a query we are not allowed to use * after select
 In general group by clause is used with group or aggregate functions .

Write a query to display no of employees working in each department?

Select deptno,count(*) from emp group by deptno

Write a query to display the no.of employees jobwise

select job,count(*) from emp group by job






No comments:

Post a Comment