human
Schema:
regions (REGION_ID, REGION_NAME)
countries (COUNTRY_ID, COUNTRY_NAME, REGION_ID)
departments (DEPARTMENT_ID, DEPARTMENT_NAME, MANAGER_ID, LOCATION_ID)
jobs (JOB_ID, JOB_TITLE, MIN_SALARY, MAX_SALARY)
employees (EMPLOYEE_ID, FIRST_NAME, LAST_NAME, EMAIL, PHONE_NUMBER, HIRE_DATE, JOB_ID, SALARY, COMMISSION_PCT, MANAGER_ID, DEPARTMENT_ID)
job_history (EMPLOYEE_ID, START_DATE, END_DATE, JOB_ID, DEPARTMENT_ID)
locations (LOCATION_ID, STREET_ADDRESS, POSTAL_CODE, CITY, STATE_PROVINCE, COUNTRY_ID)
Please answer with SQL.
assistant
Sure, I understand.
human
display the employee number and name( first name and last name ) for all employees who work in a department with any employee whose name contains a T .
assistant
SELECT employee_id , first_name , last_name FROM employees WHERE department_id IN ( SELECT department_id FROM employees WHERE first_name LIKE '%T%' )
human
display the department id and the total salary for those departments which contains at least two employees.
assistant
SELECT department_id , SUM(salary) FROM employees GROUP BY department_id HAVING count(*) >= 2
human
display job title and average salary of employees.
assistant
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
human
display the employee number, name( first name and last name ) and job title for all employees whose salary is more than any salary of those employees whose job title is PU_MAN.
assistant
SELECT employee_id , first_name , last_name , job_id FROM employees WHERE salary > ( SELECT max(salary) FROM employees WHERE job_id = 'PU_MAN' )
human
display the department ID, full name (first and last name), salary for those employees who is highest salary in every department.
assistant
SELECT first_name , last_name , salary , department_id , MAX(salary) FROM employees GROUP BY department_id
human
display the employee number, name( first name and last name ), and salary for all employees who earn more than the average salary and who work in a department with any employee with a 'J' in their first name.
assistant
SELECT employee_id , first_name , last_name , salary FROM employees WHERE salary > ( SELECT AVG ( salary ) FROM employees ) AND department_id IN ( SELECT department_id FROM employees WHERE first_name LIKE "%J%" ) ;