100% found this document useful (1 vote)
171 views7 pages

(SOLVED) LabAssignment - 02

Uploaded by

POLOK PODDAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
171 views7 pages

(SOLVED) LabAssignment - 02

Uploaded by

POLOK PODDAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Q1.

Find the first_name, last_name, email, phone_number, hire_date and


department_id of all the employees with the latest hire_date.

COMMAND:
SELECT first_name, last_name, email, phone_number, hire_date, department_id
FROM employees
ORDER BY hire_date ASC;

Q2. Find the first_name, last_name, employee_id, phone_number, salary and


department_id of all the employees with the lowest salary in each department.

COMMAND:
SELECT e1.first_name, e1.last_name, e1.employee_id, e1.phone_number, [Link],
e1.department_id
FROM employees e1
JOIN ( SELECT department_id, MIN(salary) AS min_salary
FROM employees
GROUP BY department_id) e2
ON e1.department_id = e2.department_id
AND [Link] = e2.min_salary;

Q3. Find the first_name, last_name, employee_id, commission_pct and


department_id of all the employees in the department 'DPT007' who have a lower
commission_pct than all of the employees of the department 'DPT005'.

COMMAND:

SELECT e1.first_name, e1.last_name, e1.employee_id, e1.commission_pct,


e1.department_id
FROM employees e1
WHERE e1.department_id = 'DPT007' AND e1.commission_pct < ALL (
SELECT e2.commission_pct
FROM employees e2
WHERE e2.department_id = 'DPT005'
);
Q4. Find the department_id and total number of employees of each department which
does not have a single employee under it with a salary more than 30,000.

COMMAND:
SELECT department_id, COUNT(*) AS total_employees
FROM employees
GROUP BY department_id
HAVING MAX(salary) > 30000 AND COUNT(*) > 1;

Q5. For each of the departments, find the department_id, job_id and
commission_pct with commission_pct less than at least one other job_id in that
department.

COMMAND:
SELECT e.department_id, e.job_id, e.commission_pct
FROM employees e
WHERE e.commission_pct < ANY (
SELECT commission_pct
FROM employees e2
WHERE e2.department_id = e.department_id AND e2.job_id <> e.job_id
);

Q6. Find the manager_id who does not have any employee under them with a salary
less than 3500.

COMMAND:
SELECT DISTINCT manager_id
FROM employees
WHERE manager_id IS NOT NULL
AND manager_id NOT IN (
SELECT DISTINCT manager_id
FROM employees
WHERE salary < 3500
);

Q7. Find the first_name, last_name, employee_id, email, salary, department_id and
commission_pct of the employee who has the lowest commission_pct under each
manager

COMMAND:
SELECT e1.first_name, e1.last_name, e1.employee_id, [Link], [Link],
e1.department_id, e1.commission_pct
FROM employees e1
WHERE (e1.manager_id, e1.commission_pct) IN (
SELECT e2.manager_id, MIN(e2.commission_pct)
FROM employees e2
WHERE e2.manager_id IS NOT NULL
GROUP BY e2.manager_id
);

You might also like