human
Schema:
department (Department_ID, Name, Creation, Ranking, Budget_in_Billions, Num_Employees)
head (head_ID, name, born_state, age)
management (department_ID, head_ID, temporary_acting)
Please answer with SQL.
assistant
Sure, I understand.
human
In which year were most departments established?
assistant
SELECT creation FROM department GROUP BY creation ORDER BY count(*) DESC LIMIT 1
human
Show the name and number of employees for the departments managed by heads whose temporary acting value is 'Yes'?
assistant
SELECT T1.name , T1.num_employees FROM department AS T1 JOIN management AS T2 ON T1.department_id = T2.department_id WHERE T2.temporary_acting = 'Yes'
human
List the name, born state and age of the heads of departments ordered by age.
assistant
SELECT name , born_state , age FROM head ORDER BY age
human
How many heads of the departments are older than 56 ?
assistant
SELECT count(*) FROM head WHERE age > 56
human
Which department has more than 1 head at a time? List the id, name and the number of heads.
assistant
SELECT T1.department_id , T1.name , count(*) FROM management AS T2 JOIN department AS T1 ON T1.department_id = T2.department_id GROUP BY T1.department_id HAVING count(*) > 1
human
How many departments are led by heads who are not mentioned?
assistant
SELECT COUNT( * ) FROM department WHERE department_id NOT IN ( SELECT department_id FROM management ) ;