0% found this document useful (0 votes)
3 views

DBMS-5

The document contains a report on SQL queries written by a student named Anas, focusing on various exercises related to company details. It includes multiple SQL SELECT queries to retrieve specific information such as project numbers involving employees named 'Smith', employees from Houston, and salary adjustments for those working on 'ProductX'. Each query is followed by its corresponding SQL code and intended output.

Uploaded by

neerajrahul2004
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

DBMS-5

The document contains a report on SQL queries written by a student named Anas, focusing on various exercises related to company details. It includes multiple SQL SELECT queries to retrieve specific information such as project numbers involving employees named 'Smith', employees from Houston, and salary adjustments for those working on 'ProductX'. Each query is followed by its corresponding SQL code and intended output.

Uploaded by

neerajrahul2004
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

DBMS-5

Report on SQL Queries

Name - Anas
Roll no - 23bcs083
CSE - B
Aim: Use Company details (from Lab 4) and write
appropriate query for the following
Exercises:

1. Write a SELECT query to display a list of all project numbers for projects
that
involve an employee whose last name is ‘Smith’, either as a worker or as a
manager
of the department that controls the project.

SOLUTION :-

SELECT DISTINCT P.Pnumber


FROM PROJECT P
JOIN DEPARTMENT D ON P.Dnum = D.Dnumber
JOIN EMPLOYEE E ON D.Mgr_ssn = E.Ssn
JOIN WORKS_ON W ON P.Pnumber = W.Pno
JOIN EMPLOYEE E2 ON W.Essn = E2.Ssn
WHERE E.Lname = 'Smith' OR E2.Lname = 'Smith';

Output -
2. Write a SELECT query to retrieve all employees
whose address is in Houston,Texas.

SELECT *
FROM EMPLOYEE
WHERE Address LIKE '%Houston, Texas%';

3. Write a SELECT query to find all employees who were


born during the 1950s.

SELECT *
FROM EMPLOYEE
WHERE Bdate BETWEEN '1950-01-01' AND '1959-12-31';
4. Write a SELECT query to raise 10% salary of
employees who are working on the
‘ProductX’ project and list the resulting salary along with
their names.

SELECT E.Fname, E.Lname,


E.Salary AS Original_Salary,
E.Salary * 1.1 AS Raised_Salary
FROM EMPLOYEE E
JOIN WORKS_ON W ON E.Ssn = W.Essn
JOIN PROJECT P ON W.Pno = P.Pnumber
WHERE P.Pname = 'ProductX';
5. Write a SELECT query to retrieve all employees in
department 5 whose salary is
between $30,000 and $40,000.

SELECT *
FROM EMPLOYEE
WHERE Dno = 5 AND Salary BETWEEN 30000 AND 40000;
6. Write a SELECT query to find the names of all employees
who are directly
supervised by ‘Franklin Wong’.

SELECT E.*
FROM EMPLOYEE E
JOIN EMPLOYEE Supervisor ON E.Super_ssn =
Supervisor.Ssn
WHERE Supervisor.Fname = 'Franklin' AND
Supervisor.Lname = 'Wong';

Write a SELECT query to retrieve the names of all employees


in department 5 who
work more than 10 hours per week on the ProductX project.
SELECT E.Fname, E.Lname
FROM EMPLOYEE E
JOIN WORKS_ON W ON E.Ssn = W.Essn
JOIN PROJECT P ON W.Pno = P.Pnumber
WHERE E.Dno = 5 AND P.Pname = 'ProductX' AND W.Hours
> 10;

8. List the names of all employees who have a dependent


with the same first name as
themselves.

SELECT DISTINCT E.Fname, E.Lname


FROM EMPLOYEE E
JOIN DEPENDENT D ON E.Ssn = D.Essn
WHERE E.Fname = D.Dependent_name;

You might also like