human
Schema:
Ref_Document_Types (Document_Type_Code, Document_Type_Name, Document_Type_Description)
Ref_Calendar (Calendar_Date, Day_Number)
Ref_Locations (Location_Code, Location_Name, Location_Description)
Roles (Role_Code, Role_Name, Role_Description)
All_Documents (Document_ID, Date_Stored, Document_Type_Code, Document_Name, Document_Description, Other_Details)
Employees (Employee_ID, Role_Code, Employee_Name, Gender_MFU, Date_of_Birth, Other_Details)
Document_Locations (Document_ID, Location_Code, Date_in_Location_From, Date_in_Locaton_To)
Documents_to_be_Destroyed (Document_ID, Destruction_Authorised_by_Employee_ID, Destroyed_by_Employee_ID, Planned_Destruction_Date, Actual_Destruction_Date, Other_Details)
Please answer with SQL.
assistant
Sure, I understand.
human
Show the names of all the employees with role 'HR'.
assistant
SELECT employee_name FROM Employees WHERE role_code = 'HR'
human
Show the names of employees with role name Editor.
assistant
SELECT T1.employee_name FROM Employees AS T1 JOIN ROLES AS T2 ON T1.role_code = T2.role_code WHERE T2.role_name = 'Editor'
human
What is the role code with the largest number of employees?
assistant
SELECT role_code FROM Employees GROUP BY role_code ORDER BY count(*) DESC LIMIT 1
human
Show all role codes and the number of employees in each role.
assistant
SELECT role_code , count(*) FROM Employees GROUP BY role_code
human
Show all role codes with at least 3 employees.
assistant
SELECT role_code FROM Employees GROUP BY role_code HAVING count(*) >= 3
human
Show the role code with the least employees.
assistant
SELECT role_code FROM Employees GROUP BY role_code ORDER BY COUNT( * ) ASC LIMIT 1 ;