0% found this document useful (0 votes)
12 views8 pages

DBMS - Shwet.exp3 4

The document outlines SQL queries for managing an EMPLOYEE table, including listing employees by designation, salary comparisons, and filtering based on joining dates. It also includes queries for displaying unique department numbers from both DEPT and EMP tables. The document serves as an assignment for database management system practices.

Uploaded by

ssingh21be22
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
0% found this document useful (0 votes)
12 views8 pages

DBMS - Shwet.exp3 4

The document outlines SQL queries for managing an EMPLOYEE table, including listing employees by designation, salary comparisons, and filtering based on joining dates. It also includes queries for displaying unique department numbers from both DEPT and EMP tables. The document serves as an assignment for database management system practices.

Uploaded by

ssingh21be22
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
You are on page 1/ 8

Assignment 3 & 4 ( DBMS )

Shwet Singh
102256011

Sub group – 3EC10

Create a table EMPLOYEE with following schema:


(Emp_no, E_name, E_address, E_ph_no, Dept_no, Dept_name,Job_id, Designation , Salary)
Write SQL statements for the following query.

1. List the E_no, E_name, Salary of all employees working for MANAGER.

Code:

SELECT Emp_no, E_name, Salary

FROM EMPLOYEE

WHERE Designation = 'MANAGER';

Output:

2. Display all the details of the employee whose salary is more than the Sal of any IT PROFF.

Code:

SELECT *

FROM EMPLOYEE

WHERE Salary > (SELECT MAX(Salary) FROM EMPLOYEE WHERE Designation = 'IT PROFF');

Output:
3. List the employees in the ascending order of Designations of those joined after 1981.

Code:

SELECT *

FROM EMPLOYEE

WHERE YEAR(Joining_Date) > 1981

ORDER BY Designation ASC;

Output:

4. List the employees along with their Experience and Daily Salary.

Code:

SELECT Emp_no, E_name,

DATEDIFF(CURDATE(), Joining_Date) / 365 AS Experience,

Salary / 30 AS Daily_Salary

FROM EMPLOYEE;
Output:

5. List the employees who are either ‘CLERK’ or ‘ANALYST’ .

Code:

SELECT *

FROM EMPLOYEE

WHERE Designation IN ('CLERK', 'ANALYST');

Output:

6. List the employees who joined on 1-MAY-81, 3-DEC-81, 17-DEC-81,19-JAN-80 .

Code:

SELECT *

FROM EMPLOYEE

WHERE Joining_Date IN ('1981-05-01', '1981-12-03', '1981-12-17', '1980-01-19');


Output:

7. List the employees who are working for the Deptno 10 or20.

Code:

SELECT *

FROM EMPLOYEE

WHERE Dept_no IN (10, 20);

Output:

8. List the Enames those are starting with ‘S’ .

Code:

SELECT E_name, LEFT(E_name, 5) AS First_Five_Chars

FROM EMPLOYEE

WHERE E_name LIKE 'H%';


Output:

9. Dislay the name as well as the first five characters of name(s) starting with ‘H’

Code:

SELECT E_name, LEFT(E_name, 5) AS First_Five_Chars

FROM EMPLOYEE

WHERE E_name LIKE 'H%';

Output:

10. List all the emps except ‘PRESIDENT’ & ‘MGR” in asc order of Salaries.

Code:

SELECT *

FROM EMPLOYEE

WHERE Designation NOT IN ('PRESIDENT', 'MGR')

ORDER BY Salary ASC;


Output:

Final Table:

LAB PRACTICE ASSIGNMENT:


1. Display all the dept numbers available with the dept and emp tables avoiding duplicates.

Code:

1 SELECT DISTINCT Dept_no

2 FROM (

3 SELECT Dept_no FROM DEPT

4 UNION

5 SELECT Dept_no FROM EMP

6 ) AS CombinedDeptNumbers;

Output:
2. Display all the dept numbers available with the dept and emp tables.

Code:

1 SELECT Dept_no

2 FROM (

3 SELECT Dept_no FROM DEPT

4 UNION ALL

5 SELECT Dept_no FROM EMP

6 ) AS CombinedDeptNumbers;

Output:
3. Display all the dept numbers available in emp and not in dept tables and vice versa.

Code:

1 -- Dept numbers in EMP but not in DEPT

2 SELECT Dept_no

3 FROM EMP

4 WHERE Dept_no NOT IN (SELECT Dept_no FROM DEPT)

6 UNION

8 -- Dept numbers in DEPT but not in EMP

9 SELECT Dept_no

10 FROM DEPT

11 WHERE Dept_no NOT IN (SELECT Dept_no FROM EMP);

Output:

You might also like