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

Information Management: Select From Like

1. The document provides sample SQL queries and their answers for retrieving and manipulating data from database tables. 2. Questions ask about listing employee data, joining tables, retrieving distinct project numbers, validating data, and calculating totals for hours, charges and projects. 3. Sample answers provide the necessary SQL code to select, join, group, and sort data to produce the requested results.

Uploaded by

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

Information Management: Select From Like

1. The document provides sample SQL queries and their answers for retrieving and manipulating data from database tables. 2. Questions ask about listing employee data, joining tables, retrieving distinct project numbers, validating data, and calculating totals for hours, charges and projects. 3. Sample answers provide the necessary SQL code to select, join, group, and sort data to produce the requested results.

Uploaded by

Carla Jane Roxas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Information Management

Exercise 4

1. QUESTION: Write the SQL code required to list the employee number, last

name, first name, and middle initial of all employees whose last names start

with Smith. In other words, the rows for both Smith and Smithfield should be

included in the listing. Sort the results by employee number. Assume case

sensitivity.

ANSWER:

SELECT EMP_CODE , EMP_LNAME , EMP_FNAME, EMP_INAME FROM employee WHERE

EMP_LNAME LIKE 'SMITH%';


2. QUESTION: Using the EMPLOYEE, JOB, and PROJECT tables in the

Ch07_ConstructCo database, write the SQL code that will join the EMPLOYEE and

PROJECT tables using EMP_NUM as the common attribute. Display the attributes

shown in the results presented in Figure P7.2, sorted by project value.

ANSWER:

SELECT PROJ_NAME, PROJ_VALUE, PROJ_BALANCE, EMP_LNAME, EMP_FNAME, EMP_INAME,

employee.JOB_CODE, JOB_DESCRIPTION, JOB_CHG_HR FROM project, employee, job

WHERE employee.EMP_CODE=project.EMP_CODE

AND job.JOB_CODE=employee.JOB_CODE ORDER BY PROJ_VALUE


3. QUESTION: Write the SQL code that will produce the same information that

was shown in Problem 2, but sorted by the employee’s last name.

ANSWER:

SELECT PROJ_NAME, PROJ_VALUE, PROJ_BALANCE, EMP_LNAME, EMP_FNAME, EMP_INAME,

employee.JOB_CODE, JOB_DESCRIPTION, JOB_CHG_HR FROM project, employee, job

WHERE employee.EMP_CODE=project.EMP_CODE AND job.JOB_CODE=employee.JOB_CODE

ORDER BY EMP_LNAME
4. QUESTION: Write the SQL code that will list only the distinct project

numbers in the ASSIGNMENT table, sorted by project number

ANSWER:

SELECT DISTINCT PROJ_CODE FROM assignment ORDER BY PROJ_CODE


5. QUESTION: Write the SQL code to validate the ASSIGN_CHARGE values in the

ASSIGNMENT table. Your query should retrieve the assignment number, employee

number, project number, the stored assignment charge (ASSIGN_CHARGE), and the

calculated assignment charge (calculated by multiplying ASSIGN_CHG_HR by

ASSIGN_HOURS). Sort the results by the assignment number.

ANSWER:

SELECT ASSIGN_NUM, EMP_CODE, PROJ_CODE, ASSIGN_CHARGE,

ASSIGN_CHG_HR * ASSIGN_HOURS AS SumOfCHG_HR

FROM assignment ORDER BY ASSIGN_NUM


6. QUESTION: Using the data in the ASSIGNMENT table, write the SQL code that

will yield the total number of hours worked for each employee and the total

charges stemming from those hours worked, sorted by employee number. The

results of running that query are shown in Figure P7.6

ANSWER:

SELECT assignment.EMP_CODE, EMP_LNAME,

assignment.ASSIGN_HOURS AS SumOfAssignHour,

assignment.ASSIGN_CHG_HR* assignment.ASSIGN_HOURS AS SumOfAssignCharge

FROM employee, assignment WHERE employee.EMP_CODE = assignment.EMP_CODE

GROUP BY assignment.EMP_CODE, EMP_LNAME ORDER BY assignment.EMP_CODE


7. QUESTION: Write a query to produce the total number of hours and charges

for each of the projects represented in the ASSIGNMENT table, sorted by

project number. The output is shown in Figure P7.7

ANSWER:

SELECT PROJ_CODE , SUM(ASSIGN_HOURS) AS SumOfAssignHour,

SUM(ASSIGN_CHARGE) AS SumOfAssignCharge FROM assignment GROUP BY PROJ_CODE

ORDER BY PROJ_CODE
8. QUESTION: Write the SQL code to generate the total hours worked and the

total charges made by all employees. The results are shown in Figure P7.8.

ANSWER:

SELECT SUM(ASSIGN_HOURS) AS SumOfAssignHour, SUM(ASSIGN_CHARGE) AS

SumOfAssignCharge FROM assignment

You might also like