Header Ads

Header ADS

Using the GROUP BY Clause In Oracle SQL

Using the GROUP BY Clause In Oracle SQL


Topic Introduction: The GROUP BY Clause is used to specify grouping by column. such as we want to get the department-wise total salary, or Department and job-wise total salary. In this case, we need to use the GROUP BY Clause in the SQL statement. All the columns in the SELECT list that are not in the group functions must be in the GROUP BY clause.

SELECT department_id, AVG(salary)
FROM employees
GROUP BY department_id ;

Here we have used the department_id which is not in the group functions so the department_id must be in the GROUP BY clause. We can also add more columns in the GROUP BY clause without using the SELECT clause.


Using the Group By Clause on Multiple Columns

SELECT department_id, job_id, sum(salary)
FROM employees
GROUP BY department_id, job_id
ORDER BY job_id;

In this Query Added one more column job_id with department_id now total salary will show the Department and Job Title.












No comments

Theme images by Deejpilot. Powered by Blogger.