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
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);
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
What are the maximum and minimum budget of the departments?
assistant
SELECT max(budget_in_billions) , min(budget_in_billions) FROM department
human
What are the distinct creation years of the departments managed by a secretary born in state 'Alabama'?
assistant
SELECT DISTINCT T1.creation FROM department AS T1 JOIN management AS T2 ON T1.department_id = T2.department_id JOIN head AS T3 ON T2.head_id = T3.head_id WHERE T3.born_state = 'Alabama'
human
List the creation year, name and budget of each department.
assistant
SELECT creation , name , budget_in_billions FROM department
human
In which year were most departments established?
assistant
SELECT creation FROM department GROUP BY creation ORDER BY COUNT( * ) DESC LIMIT 1 ;