Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion SQL Deep Dive/Grouping Sets/exercises.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,27 @@
* Database: Employees
* Table: Employees
*/
select grouping(e.dept_no), e.dept_no, COUNT(e.emp_no)
FROM public.dept_emp as e
GROUP BY
GROUPING SETS (
(e.dept_no),
()
)
order by e.dept_no


/*
* Calculate the total average salary per department and the total using grouping sets
* Database: Employees
* Table: Employees
*/

select grouping(de.dept_no), de.dept_no, AVG(e.salary)
FROM public.salaries as e
JOIN public.dept_emp as de USING (emp_no)
GROUP BY
GROUPING SETS (
(de.dept_no),
()
)
order by de.dept_no