Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 1. Write a query to display the last name and hire date of any employee in the same
- department as Zlotkey. Exclude Zlotkey. */
- SELECT
- last_name, hire_date
- FROM
- employees
- WHERE
- department_id = (
- SELECT
- department_id
- FROM
- employees
- WHERE
- last_name = 'Zlotkey'
- )
- AND last_name <> 'Zlotkey';
- /* 2. Create a query to display the employee numbers and last names of all employees who earn
- more than the
- average salary. Sort the results in ascending order of salary. */
- SELECT
- employee_id, last_name
- FROM
- employees
- WHERE
- salary > (
- SELECT
- AVG(salary)
- FROM
- employees
- )
- ORDER BY
- salary ASC;
- /* 3. Write a query that displays the employee numbers and last names of all employees who
- work in a department with any employee whose last name contains a “u”. */
- SELECT
- employee_id, last_name
- FROM
- employees
- WHERE
- department_id IN (
- SELECT
- department_id
- FROM
- employees
- WHERE
- last_name LIKE '%u%'
- );
- /* 4. Display the last name, department number, and job ID of all employees whose department
- location ID is 1700. */
- -- it could be done w/o subquerry (join), same for some other querries
- SELECT
- last_name, department_id, job_id
- FROM
- employees
- WHERE
- department_id IN (
- SELECT
- department_id
- FROM
- departments
- WHERE
- location_id = 1700
- );
- /* 5. Display the last name and salary of every employee whose manager is King. */
- SELECT
- last_name, salary
- FROM
- employees
- WHERE
- manager_id IN (
- SELECT
- employee_id
- FROM
- employees
- WHERE
- last_name = 'King'
- );
- /* 6. Display the department number, last name, and job ID for every employee in the
- department named “Executive”. */
- SELECT
- department_id, last_name, job_id
- FROM
- employees
- WHERE
- department_id = (
- SELECT
- department_id
- FROM
- departments
- WHERE
- department_name = 'Executive'
- );
- /* 7. Display all the employees who earn more than “Abel” */
- SELECT
- employee_id, last_name
- FROM
- employees
- WHERE
- salary > (
- SELECT
- salary
- FROM
- employees
- WHERE
- last_name = 'Abel'
- );
- /* 8 Display the employees whose job ID is the same as that of employee 141. */
- SELECT
- employee_id, last_name
- FROM
- employees
- WHERE
- job_id = (
- SELECT
- job_id
- FROM
- employees
- WHERE
- employee_id = 141
- );
- /* 9. Display employee last name, job ID, and salary of all employees whose salary
- is equal to the minimum salary */
- SELECT
- last_name, job_id, salary
- FROM
- employees
- WHERE
- salary = (
- SELECT
- MIN(salary)
- FROM
- employees
- );
- /* 10. displays all the departments that have a minimum salary greater than that of
- department 50. */
- SELECT
- department_id, MIN(salary)
- FROM
- employees
- WHERE
- department_id IS NOT NULL
- GROUP BY
- department_id
- HAVING
- MIN(salary) > (
- SELECT
- MIN(salary)
- FROM
- employees
- WHERE
- department_id = 50
- );
- /* 11. Find the employees who earn the same salary as the minimum salary for each department.
- Hint ! The main query would look like the following:
- SELECT last_name, salary, department_id
- FROM employees
- WHERE salary IN (2500, 4200, 4400, 6000, 7000, 8300, 8600, 1 7000);
- So, convert it in to subquerie. */
- SELECT
- last_name, salary, department_id
- FROM
- employees
- WHERE
- salary IN (
- SELECT
- MIN(salary)
- FROM
- employees
- GROUP BY
- department_id
- );
Advertisement
Add Comment
Please, Sign In to add comment