ICT503 Week7 Tutorial
ICT503 Week7 Tutorial
Introduction to SQL
2. What is the difference between the COUNT aggregate function and the SUM aggregate function?
3. In a SELECT query, what is the difference between a WHERE clause and a HAVING clause?
5. The ConstructCo database stores data for a consulting company that tracks all charges to
projects. The charges are based on the hours each employee works on each project. The structure
and contents of the ConstructCo database are shown in Figure 1.
Note that the ASSIGNMENT table in Figure 1 stores the JOB_CHG_HOUR values as an attribute
(ASSIGN_CHG_HR) to maintain historical accuracy of the data. The JOB_CHG_HOUR values are
likely to change over time. In fact, a JOB_CHG_HOUR change will be reflected in the ASSIGNMENT
table. Naturally, the employee primary job assignment might also change, so the ASSIGN_JOB is
1
also stored. Because those attributes are required to maintain the historical accuracy of the data,
they are not redundant.
Given the structure and contents of the ConstructCo database shown in Figure 1, use
SQL commands to answer the questions below:
5. 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.
6. Using the EMPLOYEE, JOB, and PROJECT tables in the 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 2, sorted by project
value.
Figure 2
7. Write the SQL code that will produce the same information that was shown in Figure 2, but
sorted by the employee’s last name.
8. Write the SQL code that will list only the distinct project numbers in the ASSIGNMENT table,
sorted by project number.
9. 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.
10. 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 Figure3.
2
Figure 3: