Database: cre_Doc_Tracking_DB

Question: Show all role codes and the number of employees in each role.
SQL: SELECT role_code ,  count(*) FROM Employees GROUP BY role_code

Question: What is the role code with the largest number of employees?
SQL: SELECT role_code FROM Employees GROUP BY role_code ORDER BY count(*) DESC LIMIT 1

Question: Show all role codes with at least 3 employees.
SQL: SELECT role_code FROM Employees GROUP BY role_code HAVING count(*)  >=  3

Question: Show the role code with the least employees.
SQL: SELECT role_code FROM Employees GROUP BY role_code ORDER BY count(*) ASC LIMIT 1

Question: What is the role name and role description for employee called Ebba?
SQL: SELECT T2.role_name ,  T2.role_description FROM Employees AS T1 JOIN ROLES AS T2 ON T1.role_code  =  T2.role_code WHERE T1.employee_name  =  "Ebba"

Question: Show the names of employees with role name Editor.
SQL: SELECT T1.employee_name FROM Employees AS T1 JOIN ROLES AS T2 ON T1.role_code  =  T2.role_code WHERE T2.role_name  =  "Editor"

Question: Show the employee ids for all employees with role name "Human Resource" or "Manager".
SQL: SELECT T1.employee_id FROM Employees AS T1 JOIN ROLES AS T2 ON T1.role_code  =  T2.role_code WHERE T2.role_name  =  "Human Resource" OR T2.role_name  =  "Manager"

Question: What are the different location codes for documents?
SQL: SELECT DISTINCT location_code FROM Document_locations

Question: Show the location name for document "Robin CV".
SQL: SELECT T3.location_name FROM All_documents AS T1 JOIN Document_locations AS T2 ON T1.document_id  =  T2.document_id JOIN Ref_locations AS T3 ON T2.location_code  =  T3.location_code WHERE T1.document_name  =  "Robin CV"

Question: Show the location code, the starting date and ending date in that location for all the documents.
SQL: SELECT location_code ,  date_in_location_from ,  date_in_locaton_to FROM Document_locations

Question: What is "the date in location from" and "the date in location to" for the document with name "Robin CV"?
SQL: SELECT T1.date_in_location_from ,  T1.date_in_locaton_to FROM Document_locations AS T1 JOIN All_documents AS T2 ON T1.document_id  =  T2.document_id WHERE T2.document_name  =  "Robin CV"

Question: Show the location codes and the number of documents in each location.
SQL: SELECT location_code ,  count(*) FROM Document_locations GROUP BY location_code

Question: What is the location code with the most documents?
SQL: SELECT location_code FROM Document_locations GROUP BY location_code ORDER BY count(*) DESC LIMIT 1

Question: Show the location codes with at least 3 documents.
SQL: SELECT location_code FROM Document_locations GROUP BY location_code HAVING count(*)  >=  3

Question: Show the location name and code with the least documents.
SQL: SELECT T2.location_name ,  T1.location_code FROM Document_locations AS T1 JOIN Ref_locations AS T2 ON T1.location_code  =  T2.location_code GROUP BY T1.location_code ORDER BY count(*) ASC LIMIT 1