Assignment 2a More SQL Aggregates - Solutions
Assignment 2a More SQL Aggregates - Solutions
Solutions
Solutions:
5. select dept_name,
(select count(*)
from instructor
where instructor.dept_name = department.dept_name) as num
from department
order by num desc ;
NOTE: A=B and B=C can be instead written as A=B and A=C (for
attributes of section, teaches and takes)
OR
Optional
8. Select name from instructor I1 ,
(select max(salary) as maxsal,dept_name from instructor I2 group by
dept_name ) I2
where (I2.maxsal = I1.salary and I1.dept_name = I2.dept_name );
NOTE: There are other ways to write this query. For example:
max_course_instructor can be defined without using subqueries as
max_courses as (
select max(course_count) as max_count from instr_course_count),
max_course_instructor as (
select id
from instr_course_count, ma_courses
where course_count = max_count
)