How to group and count the number in Oracle?
In Oracle, the GROUP BY clause can be used to group and calculate the count of items. It groups the result set based on specified columns and performs aggregate calculations on each group.
Here is an example query demonstrating how to use the GROUP BY clause to count the number of employees in each department in the employee table.
SELECT department_id, COUNT(*) as employee_count
FROM employees
GROUP BY department_id;
In the above query, we selected the department_id column and the COUNT() function, which is used to calculate the number of employees in each department. We then grouped the data by the department_id column using the GROUP BY clause.
Running the above query will return the department_id and the corresponding number of employees for each department.