Database: hr_1

Question: What are the employee ids for each employee and final dates of employment at their last job?
SQL: SELECT employee_id ,  MAX(end_date) FROM job_history GROUP BY employee_id

Question: What are the department ids for which more than 10 employees had a commission?
SQL: SELECT department_id FROM employees GROUP BY department_id HAVING COUNT(commission_pct) > 10

Question: What are department ids for departments with managers managing more than 3 employees?
SQL: SELECT DISTINCT department_id FROM employees GROUP BY department_id ,  manager_id HAVING COUNT(employee_id)  >= 4

Question: Give the country id and corresponding count of cities in each country.
SQL: SELECT country_id ,  COUNT(*) FROM locations GROUP BY country_id

Question: What are the job ids for jobs done more than once for a period of more than 300 days?
SQL: SELECT job_id FROM job_history WHERE end_date - start_date  > 300 GROUP BY job_id HAVING COUNT(*) >= 2

Question: What are the employee ids for employees who have held two or more jobs?
SQL: SELECT employee_id FROM job_history GROUP BY employee_id HAVING COUNT(*)  >= 2

Question: What are all the employee ids and the names of the countries in which they work?
SQL: SELECT employee_id ,  country_name FROM employees AS T1 JOIN departments AS T2 ON T1.department_id  =  T2.department_id JOIN locations AS T3 ON T2.location_id  =  T3.location_id JOIN countries AS T4 ON T3.country_id  =  T4.country_id

Question: Give the name of each department and the number of employees in each.
SQL: SELECT T2.department_name ,  COUNT(*) FROM employees AS T1 JOIN departments AS T2 ON T1.department_id  =  T2.department_id GROUP BY T2.department_name

Question: What is the average salary for each job title?
SQL: SELECT job_title ,  AVG(salary) FROM employees AS T1 JOIN jobs AS T2 ON T1.job_id  =  T2.job_id GROUP BY T2.job_title

Question: Provide the full names of employees earning more than the employee with id 163.
SQL: SELECT first_name ,  last_name FROM employees WHERE salary  >  (SELECT salary FROM employees WHERE employee_id = 163 )

Question: What is the minimum salary in each department?
SQL: SELECT MIN(salary) ,  department_id FROM employees GROUP BY department_id

Question: What are the full names and department ids for the lowest paid employees across all departments.
SQL: SELECT first_name ,  last_name ,  department_id FROM employees WHERE salary IN (SELECT MIN(salary) FROM employees GROUP BY department_id)

Question: What are the employee ids for employees who make more than the average?
SQL: SELECT employee_id FROM employees WHERE salary  >  (SELECT AVG(salary) FROM employees)

Question: What are the employee ids of employees who report to Payam, and what are their salaries?
SQL: SELECT employee_id ,  salary FROM employees WHERE manager_id  =  (SELECT employee_id FROM employees WHERE first_name  =  'Payam' )

Question: What are the names of departments that have at least one employee.
SQL: SELECT DISTINCT T2.department_name FROM employees AS T1 JOIN departments AS T2 ON T1.department_id  =  T2.department_id