SELECT with GROUP BY clause
GROUP
BY Clause is used with the group functions to retrieve data grouped according
to one or more columns.
Syntax
:
SELECT
col1, group function(col2), .. FROM
<tablename> GROUP BY column specified in select.
Examples
:
1) Total
salary of the all employees
SQL> SELECT
SUM(salary) from emp;
2) Total
salary departmentwise
SQL> SELECT dept, SUM(salary)
from emp GROUP BY dept;
3)
Number of employees in each location
SQL> SELECT
location,count(*) FROM emp GROUP BY location;
4)
Average age of employess
SQL> SELECT Avg(age) from emp;
5)
Number of employess joined on each date
SQL> SELECT
hiredate,count(*) FROM emp group by hiredate;
No comments:
Post a Comment