SQL_QUIRIES
SQL_QUIRIES
SS Chung
The typical SQL commands (DDL) for this lab are as follow:
The typical SQL commands (DML) to populate a table and show the rows inserted into the table
for this task are like the following example.
Show your SQL statements and the result in a Word document. Add screenshots showing your
SQLs and the results to show the content of each table after populating it.
3-1) Write SQL using a view named VDept_Headcount that reports headcount for each
department. The report includes 3 columns as follow:
Dept_Name, Dept_Number, No_Emp.
Include all the departments.
3-2)
1) Add yourself to the database (Employee, Dependent, Works_On). Enter some
assignments, and family members.
2) Change your view to add one more info - Salary_Budget as total salary for each department.
Include all the departments. Your report lists 4 Columns as follow:
Dept_Name, Dept_Number, No_Emp, Salary_Budget
3) Run the same query that you wrote in 3-1) to report the updated info after changes in the
database.
Show your SQL statements and the result in a Word document. Add screenshots showing your
SQLs and the results to show your report is updated before and after the changes in the
database.
Add these new entries into Dependent, Works_On tables in your database then Select * from
Dependent and Select * from Works_On to show the updated table contents.
Q1:
Make a list of all project numbers that Research department employees are working on,
either as a worker or as a manager of the department that controls the projects.
Q2:
Get SSN and the last name of married female employees who work on three or more
projects
Q3. Write SQL using View instead of Subquery (the part to find the employees who are
working on three more projects) to express the same query Q2.
Q4:
Get the last name of married employees who only have daughters.
1. Your query and the result of your query for each question
2. Make a screenshot of each query and its result returned in one window to show
your query successfully returns the correct result.
3. Add comments, if needed, explaining the meaning of each component included
in the report.
4. Turn in a Printout of your report in Class for grading
5. Submit your lab report files on Blackboard for a timestamp
Figure 2. COMPANY SCHEMA - ER Diagram
EMPLOYEE
FNAME MINIT LNAME SSN BDATE ADDRESS SEX SALARY SUPERSSN DNO
John B Smith 123456789 09-Jan-55 731 Fondren, Houston, TX M 30000 987654321 5
Franklin T Wong 333445555 08-Dec-45 638 Voss, Houston, TX M 40000 888665555 5
Joyce A English 453453453 31-Jul-62 5631 Rice, Houston, TX F 25000 333445555 5
Ramesh K Narayan 666884444 15-Sep-52 975 Fire Oak, Humble, TX M 38000 333445555 5
James E Borg 888665555 10-Nov-27 450 Stone, Houston, TX M 55000 1
Jennifer S Wallace 987654321 20-Jun-31 291 Berry, Bellaire, TX F 43000 888665555 4
Ahmad V Jabbar 987987987 29-Mar-59 980 Dallas, Houston, TX M 25000 987654321 4
Alicia J Zelaya 999887777 19-Jul-58 3321 Castle, SPring, TX F 25000 987654321 4
DEPARTMENT
DNAME DNUMBER MGRSSN MGRSTARTDATE
Headquarters 1 888665555 19-Jun-71
Administration 4 987654321 01-Jan-85
Research 5 333445555 22-May-78
Automation 7 123456789 06-Oct-05
DEPENDENT
ESSN DEPENDENT_NAME SEX BDATE RELATIONSHIP
123456789 Alice F 31-Dec-78 Daughter
123456789 Elizabeth F 05-May-57 Spouse
123456789 Michael M 01-Jan-78 Son
333445555 Alice F 05-Apr-76 Daughter
333445555 Joy F 03-May-48 Spouse
333445555 Theodore M 25-Oct-73 Son
987654321 Abner M 29-Feb-32 Spouse
DEPT_LOCATIONS
DNUMBER DLOCATION
1 Houston
4 Stafford
5 Bellaire
5 Sugarland
5 Houston
PROJECT
PNAME PNUMBER PLOCATION DNUM
ProductX 1 Bellaire 5
ProductY 2 Sugarland 5
ProductZ 3 Houston 5
Computerization 10 Stafford 4
Reorganization 20 Houston 1
Newbenefits 30 Stafford 4
WORKS_ON
ESSN PNO Hours
123456789 1 32.5
123456789 2 7.5
333445555 2 10
333445555 3 10
333445555 10 10
333445555 20 10
453453453 1 20
453453453 2 20
666884444 3 40
888665555 20
987654321 20 15
987654321 30 20
987987987 10 35
987987987 30 5
999887777 10 10
999887777 30 30