Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
40 views4 pages

Assignment No 6

Uploaded by

profoundrec11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
40 views4 pages

Assignment No 6

Uploaded by

profoundrec11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
LAB PRACTICE ASSIGNMENT CREATE TABLE employees CREATE TABLE employees (emp_id INT PRIMARY KEY,emp_name VARCHAR(50),job_category VARCHAR(50) salary DECIMAL(10, 2),manager_id INT,department_id INT); INSERT VALUES INTO employees INSERT INTO employees values(1, ‘Alice’, 'Manager’, 3000.00, NULL, 1); INSERT INTO employees values(2, ‘Bob’, ‘Manager’, 28000.00, NULL, 2); INSERT INTO employees values(3, ‘Charlie’, Developer’, 25000.00, 1, 1); INSERT INTO employees values (4, ‘David’, ‘Developer’, 2300.00, 1, 1); INSERT INTO employees values (5, 'Eve', ‘Analyst’, 2000.00, 2, 2); INSERT INTO employees values (6, 'Frank’ ‘Analyst’, 1900.00, 2, 2); EMP_ID EMP_NAME JOB CATEGORY SALARY MANAGER_ID DEPARTMENT ID 1 Alice Manager 30000 = 1 2 Bob Manager 20000 - 2 3 Charlo Developer 25000 1 1 4 David Developer 23000 1 1 5 Eve Analyst 20000 2 2 6 Frank Analyst 190002 2 CREATE TABLE departments CREATE TABLE departments (department_id INT PRIMARY KEY. department_name VARCHAR(50)); INSERT VALUES INTO employees INSERT INTO departments VALUES(1, ‘Engineering’); INSERT INTO departments VALUES (2, ‘Finance'); DEPARTMENT_ID DEPARTMENT_NAME 1 Engineering 2 Finance Q1)Display total salary spent for each job category. Query : SELECT job_category, SUM(salary) AS total_salary FROM employees GROUP BY job_category; JOB_CATEGORY TOTAL_SALARY Manager 58000 Analyst 39000 Developer 48000 Q2)Display lowest paid employee details under each manager. Query : SELECT e.manager_id, e.emp_id, e.emp_name, e.salary FROM employees e WHERE e.salary =(SELECT MIN(salary)FROM employees WHERE manager_id = e.manager_id); MANAGER_ID EMP_ID EMP_NAME SALARY 1 4 David 23000 Z 6 Frank 19000 Q3)Display number of employees working in each department and their department name. Query : SELECT d.department_name, COUNT(e.emp_id) AS num_employees FROM departments d LEFT JOIN employees e ON d.department_id = e.department_id GROUP BY d.department_name; DEPARTMENT_NAME NUM_EMPLOYEES Finance 3 Engineering 3 a4) play the details of employees sorting the salary in increasing order. Query : SELECT emp_id, emp_name, job_category, salary FROM employees ORDER BY salary ASC; EMP_ID EMP_NAME JOB_CATEGORY SALARY 6 Frank Analyst 19000 5 Eve Analyst 20000 4 David Davalopar 23000 3 Charlie Developer 25000 2 Bob Manager 28000 1 Alice Manager 30000 Q5)Show the record of employee earning salary greater than 16000 in each department. Query : SELECT d.department_name, e.emp_id, e.emp_name, e.salary FROM departments d JOIN employees e ON d.department_id = e.department_id WHERE e.salary > 16000: DEPARTMENT_NAME EMP_ID EMP_NAME SALARY Engineering 1 Alice 30000 Finance 2 Bob 28000 Engineering 3 Charlie 26000 Engineering 4 David 23000 Finance 5 Eve 20000 Finance 6 Frank ‘19000

You might also like