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

ICT503 Week7 Tutorial

Uploaded by

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

ICT503 Week7 Tutorial

Uploaded by

Arsalan Chaudhry
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Week-7 Tutorial

Introduction to SQL

1. Explain the difference between an ORDER BY clause and a GROUP BY clause.

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?

4. What is a subquery, and what are its basic characteristics?

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.

Figure 1: ConstructCo Database

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:

1. Download the following file from the Moodle: 07_ConstructCo_mysql_txt.


2. Import file into XAMPP.
3. Write a query to count the number of projects.
4. Write a query to count the number of Employees with the Assign charge more than 150.

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:

You might also like