SlideShare a Scribd company logo
Visit https://testbankfan.com to download the full version and
browse more test banks or solution manuals
Database Systems Design Implementation and
Management 11th Edition Coronel Solutions Manual
_____ Press the link below to begin your download _____
https://testbankfan.com/product/database-systems-design-
implementation-and-management-11th-edition-coronel-
solutions-manual/
Access testbankfan.com now to download high-quality
test banks or solution manuals
Here are some recommended products for you. Click the link to
download, or explore more at testbankfan.com
Database Systems Design Implementation and Management 11th
Edition Coronel Test Bank
https://testbankfan.com/product/database-systems-design-
implementation-and-management-11th-edition-coronel-test-bank/
Database Systems Design Implementation and Management 12th
Edition Coronel Solutions Manual
https://testbankfan.com/product/database-systems-design-
implementation-and-management-12th-edition-coronel-solutions-manual/
Database Systems Design Implementation And Management 13th
Edition Coronel Solutions Manual
https://testbankfan.com/product/database-systems-design-
implementation-and-management-13th-edition-coronel-solutions-manual/
Business Law in Canada Canadian Edition Canadian 10th
Edition Yates Test Bank
https://testbankfan.com/product/business-law-in-canada-canadian-
edition-canadian-10th-edition-yates-test-bank/
Modern Advanced Accounting in Canada Canadian 7th Edition
Hilton Solutions Manual
https://testbankfan.com/product/modern-advanced-accounting-in-canada-
canadian-7th-edition-hilton-solutions-manual/
Information Systems A Managers Guide to Harnessing
Technology 1st Edition Gallaugher Test Bank
https://testbankfan.com/product/information-systems-a-managers-guide-
to-harnessing-technology-1st-edition-gallaugher-test-bank/
Organizations Behavior Structure Processes 14th Edition
Gibson Test Bank
https://testbankfan.com/product/organizations-behavior-structure-
processes-14th-edition-gibson-test-bank/
Finite Mathematics and Its Applications 12th Edition
Goldstein Solutions Manual
https://testbankfan.com/product/finite-mathematics-and-its-
applications-12th-edition-goldstein-solutions-manual/
Human Resource Information Systems 3rd Edition Kavanagh
Test Bank
https://testbankfan.com/product/human-resource-information-
systems-3rd-edition-kavanagh-test-bank/
Chemistry An Atoms First Approach 2nd Edition Zumdahl
Solutions Manual
https://testbankfan.com/product/chemistry-an-atoms-first-approach-2nd-
edition-zumdahl-solutions-manual/
Chapter 7 An Introduction to Structured Query Language (SQL)
239
Chapter 7
Introduction to Structured Query Language (SQL)
NOTE
Several points are worth emphasizing:
• We have provided the SQL scripts for both chapters 7 and 8. These scripts are intended to
facilitate the flow of the material presented to the class. However, given the comments made
by our students, the scripts should not replace the manual typing of the SQL commands by
students. Some students learn SQL better when they have a chance to type their own
commands and get the feedback provided by their errors. We recommend that the students use
their lab time to practice the commands manually.
• Because this chapter focuses on learning SQL, we recommend that you use the Microsoft
Access SQL window to type SQL queries. Using this approach, you will be able to
demonstrate the interoperability of standard SQL. For example, you can cut and paste the same
SQL command from the SQL query window in Microsoft Access, to Oracle SQL * Plus and to
MS SQL Query Analyzer. This approach achieves two objectives:
➢ It demonstrates that adhering to the SQL standard means that most of the SQL code
will be portable among DBMSes.
➢ It also demonstrates that even a widely accepted SQL standard is sometimes
implemented with slight distinctions by different vendors. For example, the treatment
of date formats in Microsoft Access and Oracle is slightly different.
Answers to Review Questions
1. In a SELECT query, what is the difference between a WHERE clause and a HAVING clause?
Both a WHERE clause and a HAVING clause can be used to eliminate rows from the results of a
query. The differences are 1) the WHERE clause eliminates rows before any grouping for aggregate
functions occurs while the HAVING clause eliminates groups after the grouping has been done, and
2) the WHERE clause cannot contain an aggregate function but the HAVING clause can.
2. Explain why the following command would create an error, and what changes could be made
to fix the error.
SELECT V_CODE, SUM(P_QOH) FROM PRODUCT;
The command would generate an error because an aggregate function is applied to the P_QOH
attribute but V_CODE is neither in an aggregate function or in a GROUP BY. This can be fixed by
either 1) placing V_CODE in an appropriate aggregate function based on the data that is being
requested by the user, 2) adding a GROUP BY clause to group by values of V_CODE (i.e. GROUP
BY V_CODE), 3) removing the V_CODE attribute from the SELECT clause, or 4) removing the
Sum aggregate function from P_QOH. Which of these solutions is most appropriate depends on the
question that the query was intended to answer.
Chapter 7 An Introduction to Structured Query Language (SQL)
240
3. What type of integrity is enforced when a primary key is declared?
Creating a primary key constraint enforces entity integrity (i.e. no part of the primary key can
contain a null and the primary key values must be unique).
4. Explain why it might be more appropriate to declare an attribute that contains only digits as a
character data type instead of a numeric data type.
An attribute that contains only digits may be properly defined as character data when the values are
nominal; that is, the values do not have numerical significance but serve only as labels such as ZIP
codes and telephone numbers. One easy test is to consider whether or not a leading zero should be
retained. For the ZIP code 03133, the leading zero should be retained; therefore, it is appropriate to
define it as character data. For the quantity on hand of 120, we would not expect to retain a leading
zero such as 0120; therefore, it is appropriate to define the quantity on hand as a numeric data type.
5. What is the difference between a column constraint and a table constraint?
A column constraint can refer to only the attribute with which it is specified. A table constraint can
refer to any attributes in the table.
6. What are “referential constraint actions”?
Referential constraint actions, such as ON DELETE CASCADE, are default actions that the DBMS
should take when a DML command would result in a referential integrity constraint violation.
Without referential constraint actions, DML commands that would result in a violation of referential
integrity will fail with an error indicating that the referential integrity constrain cannot be violated.
Referential constraint actions can allow the DML command to successfully complete while making
the designated changes to the related records to maintain referential integrity.
7. Rewrite the following WHERE clause without the use of the IN special operator.
WHERE V_STATE IN (‘TN’, ‘FL’, ‘GA’)
WHERE V_STATE = 'TN' OR V_STATE = 'FL' OR V_STATE = 'GA'
Notice that each criteria must be complete (i.e. attribute-operator-value).
8. Explain the difference between an ORDER BY clause and a GROUP BY clause.
An ORDER BY clause has no impact on which rows are returned by the query, it simply sorts those
rows into the specified order. A GROUP BY clause does impact the rows that are returned by the
query. A GROUP BY clause gathers rows into collections that can be acted on by aggregate
functions.
9. Explain why the two following commands produce different results.
SELECT DISTINCT COUNT (V_CODE) FROM PRODUCT;
Chapter 7 An Introduction to Structured Query Language (SQL)
241
SELECT COUNT (DISTINCT V_CODE) FROM PRODUCT;
The difference is in the order of operations. The first command executes the Count function to count
the number of values in V_CODE (say the count returns "14" for example) including duplicate
values, and then the Distinct keyword only allows one count of that value to be displayed (only one
row with the value "14" appears as the result). The second command applies the Distinct keyword to
the V_CODEs before the count is taken so only unique values are counted.
10. What is the difference between the COUNT aggregate function and the SUM aggregate
function?
COUNT returns the number of values without regard to what the values are. SUM adds the values
together and can only be applied to numeric values.
11. Explain why it would be preferable to use a DATE data type to store date data instead of a
character data type.
The DATE data type uses numeric values based on the Julian calendar to store dates. This makes
date arithmetic such as adding and subtracting days or fractions of days possible (as well as
numerous special date-oriented functions discussed in the next chapter!).
12. What is a recursive join?
A recursive join is a join in which a table is joined to itself.
Problem Solutions
O n l i n e C o n t e n t
Problems 1 – 25 are based on the Ch07_ConstructCo database located www.cengagebrain.com. This database
is stored in Microsoft Access format. The website provides Oracle, MySQL, and MS SQL Server script files.
The Ch07_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 Ch07_ConstructCo database are shown in Figure P7.1.
Figure P7.1 Structure and contents of the Ch07_ConstructCo database
Chapter 7 An Introduction to Structured Query Language (SQL)
242
Note that the ASSIGNMENT table in Figure P7.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. And, naturally, the employee primary job assignment
might change, so the ASSIGN_JOB is 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 Ch07_ConstructCo database shown in Figure P7.1, use
SQL commands to answer Problems 1–25.
1. Write the SQL code that will create the table structure for a table named EMP_1. This table is
a subset of the EMPLOYEE table. The basic EMP_1 table structure is summarized in the table
below. (Note that the JOB_CODE is the FK to JOB.)
Chapter 7 An Introduction to Structured Query Language (SQL)
243
ATTRIBUTE (FIELD) NAME DATA DECLARATION
EMP_NUM CHAR(3)
EMP_LNAME VARCHAR(15)
EMP_FNAME VARCHAR(15)
EMP_INITIAL CHAR(1)
EMP_HIREDATE DATE
JOB_CODE CHAR(3)
CREATE TABLE EMP_1 (
EMP_NUM CHAR(3) PRIMARY KEY,
EMP_LNAME VARCHAR(15) NOT NULL,
EMP_FNAME VARCHAR(15) NOT NULL,
EMP_INITIAL CHAR(1),
EMP_HIREDATE DATE,
JOB_CODE CHAR(3),
FOREIGN KEY (JOB_CODE) REFERENCES JOB);
NOTE
We have already provided the EMP_1 table for you. If you try to run the preceding query,
you will get an error message because the EMP_1 table already exits.
2. Having created the table structure in Problem 1, write the SQL code to enter the first two rows
for the table shown in Figure P7.2.
Figure P7.2 The contents of the EMP_1 table
INSERT INTO EMP_1 VALUES (‘101’, ‘News’, ‘John’, ‘G’, ’08-Nov-00’, ‘502’);
INSERT INTO EMP_1 VALUES (‘102’, ‘Senior’, ‘David’, ‘H’, ’12-Jul-89’, ‘501’);
3. Assuming the data shown in the EMP_1 table have been entered, write the SQL code that will
list all attributes for a job code of 502.
SELECT *
FROM EMP_1
WHERE JOB_CODE = ‘502’;
Chapter 7 An Introduction to Structured Query Language (SQL)
244
4. Write the SQL code that will save the changes made to the EMP_1 table.
COMMIT;
5. Write the SQL code to change the job code to 501 for the person whose employee number
(EMP_NUM) is 107. After you have completed the task, examine the results, and then reset the
job code to its original value.
UPDATE EMP_1
SET JOB_CODE = ‘501’
WHERE EMP_NUM = ‘107’;
To see the changes:
SELECT *
FROM EMP_1
WHERE EMP_NUM = ‘107’;
To reset, use
ROLLBACK;
6. Write the SQL code to delete the row for the person named William Smithfield, who was hired
on June 22, 2004, and whose job code classification is 500. (Hint: Use logical operators to
include all of the information given in this problem.)
DELETE FROM EMP_1
WHERE EMP_LNAME = 'Smithfield'
AND EMP_FNAME = 'William'
AND EMP_HIREDATE = '22-June-04'
AND JOB_CODE = '500';
7. Write the SQL code that will restore the data to its original status; that is, the table should
contain the data that existed before you made the changes in Problems 5 and 6.
ROLLBACK;
Chapter 7 An Introduction to Structured Query Language (SQL)
245
8. Write the SQL code to create a copy of EMP_1, naming the copy EMP_2. Then write the SQL
code that will add the attributes EMP_PCT and PROJ_NUM to its structure. The EMP_PCT
is the bonus percentage to be paid to each employee. The new attribute characteristics are:
EMP_PCTNUMBER(4,2)
PROJ_NUMCHAR(3)
(Note: If your SQL implementation allows it, you may use DECIMAL(4,2) rather than
NUMBER(4,2).)
There are two way to get this job done. The two possible solutions are shown next.
Solution A:
CREATE TABLE EMP_2 (
EMP_NUM CHAR(3) NOT NULL UNIQUE,
EMP_LNAME VARCHAR(15) NOT NULL,
EMP_FNAME VARCHAR(15) NOT NULL,
EMP_INITIAL CHAR(1),
EMP_HIREDATE DATE NOT NULL,
JOB_CODE CHAR(3) NOT NULL,
PRIMARY KEY (EMP_NUM),
FOREIGN KEY (JOB_CODE) REFERENCES JOB);
INSERT INTO EMP_2 SELECT * FROM EMP_1;
ALTER TABLE EMP_2
ADD (EMP_PCT NUMBER (4,2)),
ADD (PROJ_NUM CHAR(3));
Solution B:
CREATE TABLE EMP_2 AS SELECT * FROM EMP_1;
ALTER TABLE EMP_2
ADD (EMP_PCT NUMBER (4,2)),
ADD (PROJ_NUM CHAR(3));
9. Write the SQL code to change the EMP_PCT value to 3.85 for the person whose employee
number (EMP_NUM) is 103. Next, write the SQL command sequences to change the
EMP_PCT values as shown in Figure P7.9.
Chapter 7 An Introduction to Structured Query Language (SQL)
246
Figure P7.9 The contents of the EMP_2 table
UPDATE EMP_2
SET EMP_PCT = 3.85
WHERE EMP_NUM = '103';
To enter the remaining EMP_PCT values, use the following SQL statements:
UPDATEEMP_2
SET EMP_PCT = 5.00
WHERE EMP_NUM = ‘101’;
UPDATEEMP_2
SET EMP_PCT = 8.00
WHERE EMP_NUM = ‘102’;
Follow this format for the remaining rows.
10. Using a single command sequence, write the SQL code that will change the project number
(PROJ_NUM) to 18 for all employees whose job classification (JOB_CODE) is 500.
UPDATE EMP_2
SET PROJ_NUM = '18'
WHERE JOB_CODE = '500';
11. Using a single command sequence, write the SQL code that will change the project number
(PROJ_NUM) to 25 for all employees whose job classification (JOB_CODE) is 502 or higher.
When you finish Problems 10 and 11, the EMP_2 table will contain the data shown in Figure
P7.11. (You may assume that the table has been saved again at this point.)
Chapter 7 An Introduction to Structured Query Language (SQL)
247
Figure P7.11 The EMP_2 table contents after the modification
UPDATE EMP_2
SET PROJ_NUM = '25'
WHERE JOB_CODE > = '502'
12. Write the SQL code that will change the PROJ_NUM to 14 for those employees who were
hired before January 1, 1994 and whose job code is at least 501. (You may assume that the
table will be restored to its condition preceding this question.)
UPDATE EMP_2
SET PROJ_NUM = '14'
WHERE EMP_HIREDATE <= ' 01-Jan-94'
AND JOB_CODE >= '501';
13. Write the two SQL command sequences required to:
There are many ways to accomplish both tasks. We are illustrating the shortest way to do the job
next.
a. Create a temporary table named TEMP_1 whose structure is composed of the EMP_2
attributes EMP_NUM and EMP_PCT.
The SQL code shown in problem 13b contains the solution for problem 13a.
b. Copy the matching EMP_2 values into the TEMP_1 table.
CREATE TABLE TEMP_1 AS SELECT EMP_NUM, EMP_PCT FROM EMP_2;
An alternate way would be to create the table and then, use an INSERT with a sub-select to
populate the rows.
CREATE TABLE TEMP_1 AS (
EMP_NUM CHAR(3),
EMP_PCT NUMBER(4,2));
INSERT INTO TEMP_1
SELECT EMP_NUM, EMP_PCT FROM EMP_2;
Chapter 7 An Introduction to Structured Query Language (SQL)
248
14. Write the SQL command that will delete the newly created TEMP_1 table from the database.
DROP TABLE TEMP_1;
15. Write the SQL code required to list all employees whose last names start with Smith. In other
words, the rows for both Smith and Smithfield should be included in the listing. Assume case
sensitivity.
SELECT *
FROM EMP_2
WHERE EMP_LNAME LIKE 'Smith%';
16. Using the EMPLOYEE, JOB, and PROJECT tables in the Ch07_ConstructCo database (see
Figure P7.1), write the SQL code that will produce the results shown in Figure P7.16.
Figure P7.16 The query results for Problem 16
SELECT PROJ_NAME, PROJ_VALUE, PROJ_BALANCE, EMPLOYEE.EMP_LNAME,
EMP_FNAME, EMP_INITIAL, EMPLOYEE.JOB_CODE, JOB.JOB_DESCRIPTION,
JOB.JOB_CHG_HOUR
FROM PROJECT, EMPLOYEE, JOB
WHERE EMPLOYEE.EMP_NUM = PROJECT.EMP_NUM
AND JOB.JOB_CODE = EMPLOYEE.JOB_CODE;
17. Write the SQL code that will produce a virtual table named REP_1. The virtual table should
contain the same information that was shown in Problem 16.
CREATE VIEW REP_1 AS
SELECT PROJ_NAME, PROJ_VALUE, PROJ_BALANCE, EMPLOYEE.EMP_LNAME,
EMP_FNAME, EMP_INITIAL, EMPLOYEE.JOB_CODE, JOB.JOB_DESCRIPTION,
JOB.JOB_CHG_HOUR
FROM PROJECT, EMPLOYEE, JOB
WHERE EMPLOYEE.EMP_NUM = PROJECT.EMP_NUM
AND JOB.JOB_CODE = EMPLOYEE.JOB_CODE;
Chapter 7 An Introduction to Structured Query Language (SQL)
249
18. Write the SQL code to find the average bonus percentage in the EMP_2 table you created in
Problem 8.
SELECT AVG(EMP_PCT)
FROM EMP_2;
19. Write the SQL code that will produce a listing for the data in the EMP_2 table in ascending
order by the bonus percentage.
SELECT *
FROM EMP_2
ORDER BY EMP_PCT;
20. Write the SQL code that will list only the distinct project numbers found in the EMP_2 table.
SELECT DISTINTC PROJ_NUM
FROM EMP_2;
21. Write the SQL code to calculate the ASSIGN_CHARGE values in the ASSIGNMENT table in
the Ch07_ConstructCo database. (See Figure P7.1.) Note that ASSIGN_CHARGE is a derived
attribute that is calculated by multiplying ASSIGN_CHG_HR by ASSIGN_HOURS.
UPDATE ASSIGNMENT
SET ASSIGN_CHARGE = ASSIGN_CHG_HR * ASSIGN_HOURS;
22. 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.
The results of running that query are shown in Figure P7.22.
Figure P7.22 Total hours and charges by employee
Chapter 7 An Introduction to Structured Query Language (SQL)
250
SELECT ASSIGNMENT.EMP_NUM, EMPLOYEE.EMP_LNAME,
Sum(ASSIGNMENT.ASSIGN_HOURS) AS SumOfASSIGN_HOURS,
Sum(ASSIGNMENT.ASSIGN_CHARGE) AS SumOfASSIGN_CHARGE
FROM EMPLOYEE, ASSIGNMENT
WHERE EMPLOYEE.EMP_NUM = ASSIGNMENT.EMP_NUM
GROUP BY ASSIGNMENT.EMP_NUM, EMPLOYEE.EMP_LNAME;
23. Write a query to produce the total number of hours and charges for each of the projects
represented in the ASSIGNMENT table. The output is shown in Figure P7.23.
Figure P7.23 Total hour and charges by project
SELECT ASSIGNMENT.PROJ_NUM,
Sum(ASSIGNMENT.ASSIGN_HOURS) AS SumOfASSIGN_HOURS,
Sum(ASSIGNMENT.ASSIGN_CHARGE) AS SumOfASSIGN_CHARGE
FROM ASSIGNMENT
GROUP BY ASSIGNMENT.PROJ_NUM
24. 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.24. (Hint: This is a nested query. If you use
Microsoft Access, you can generate the result by using the query output shown in Figure P7.22
as the basis for the query that will produce the output shown in Figure P7.24.)
Figure P7.24 Total hours and charges, all employees
Solution A:
SELECT Sum(SumOfASSIGN_HOURS) AS SumOfASSIGN_HOURS,
Sum(SumOfASSIGN_CHARGE) AS SumOfASSIGN_CHARGE
FROM Q23;
or
Chapter 7 An Introduction to Structured Query Language (SQL)
251
SELECT Sum(SumOfASSIGN_HOURS) AS SumOfASSIGN_HOURS,
Sum(SumOfASSIGN_CHARGE as SumOfASSIGN_CHARGE
FROM (SELECT ASSIGNMENT.PROJ_NUM,
Sum(ASSIGNMENT.ASSIGN_HOURS) AS SumOfASSIGN_HOURS,
Sum(ASSIGNMENT.ASSIGN_CHARGE) AS
SumOfASSIGN_CHARGE
FROM ASSIGNMENT
GROUP BY ASSIGNMENT.PROJ_NUM
);
Solution B:
SELECT Sum(SumOfASSIGN_HOURS) AS SumOfASSIGN_HOURS,
Sum(SumOfASSIGN_CHARGE) AS SumOfASSIGN_CHARGE
FROM Q22;
or
SELECT Sum(SumOfASSIGN_HOURS) AS SumOfASSIGN_HOURS,
Sum(SumOfASSIGN_CHARGE) AS SumOfASSIGN_CHARGE
FROM (SELECT ASSIGNMENT.EMP_NUM, EMPLOYEE.EMP_LNAME,
Sum(ASSIGNMENT.ASSIGN_HOURS) AS SumOfASSIGN_HOURS,
Sum(ASSIGNMENT.ASSIGN_CHARGE) AS
SumOfASSIGN_CHARGE
FROM EMPLOYEE, ASSIGNMENT
WHERE EMPLOYEE.EMP_NUM = ASSIGNMENT.EMP_NUM
GROUP BY ASSIGNMENT.EMP_NUM, EMPLOYEE.EMP_LNAME
);
Chapter 7 An Introduction to Structured Query Language (SQL)
252
25. Write the SQL code to generate the total hours worked and the total charges made to all
projects. The results should be the same as those shown in Figure P7.24. (Hint: This is a nested
query. If you use Microsoft Access, you can generate the result by using the query output
shown in Figure P7.23 as the basis for this query.)
SELECT Sum(SumOfASSIGN_HOURS) AS SumOfASSIGN_HOURS,
Sum(SumOfASSIGN_CHARGE) AS SumOfASSIGN_CHARGE
FROM Q23;
or
SELECT Sum(SumOfASSIGN_HOURS) AS SumOfASSIGN_HOURS,
Sum(SumOfASSIGN_CHARGE as SumOfASSIGN_CHARGE
FROM (SELECT ASSIGNMENT.PROJ_NUM,
Sum(ASSIGNMENT.ASSIGN_HOURS) AS SumOfASSIGN_HOURS,
Sum(ASSIGNMENT.ASSIGN_CHARGE) AS
SumOfASSIGN_CHARGE
FROM ASSIGNMENT
GROUP BY ASSIGNMENT.PROJ_NUM
);
O n l i n e C o n t e n t
Problems 26−43 are based on the Ch07_SaleCo database, which is available at www.cengagebrain.com.
This database is stored in Microsoft Access format. Oracle, MySQL and MS SQL Server script files are
available at www.cengagebrain.com.
The structure and contents of the Ch07_SaleCo database are shown in Figure P7.26. Use this
database to answer the following problems. Save each query as QXX, where XX is the problem
number.
26. Write a query to count the number of invoices.
SELECT COUNT(*) FROM INVOICE;
27. Write a query to count the number of customers with a customer balance over $500.
SELECT COUNT(*)
FROM CUSTOMER
WHERE CUS_BALANCE >500;
Chapter 7 An Introduction to Structured Query Language (SQL)
253
28. Generate a listing of all purchases made by the customers, using the output shown in Figure
P7.28 as your guide. (Hint: Use the ORDER BY clause to order the resulting rows as shown in
Figure P7.28)
FIGURE P7.28 List of Customer Purchases
SELECT INVOICE.CUS_CODE, INVOICE.INV_NUMBER, INVOICE.INV_DATE,
PRODUCT.P_DESCRIPT, LINE.LINE_UNITS, LINE.LINE_PRICE
FROM CUSTOMER, INVOICE, LINE, PRODUCT
WHERE CUSTOMER.CUS_CODE = INVOICE.CUS_CODE
AND INVOICE.INV_NUMBER = LINE.INV_NUMBER
AND PRODUCT.P_CODE = LINE.P_CODE
ORDER BY INVOICE.CUS_CODE, INVOICE.INV_NUMBER, PRODUCT.P_DESCRIPT;
Chapter 7 An Introduction to Structured Query Language (SQL)
254
29. Using the output shown in Figure P7.29 as your guide, generate the listing of customer
purchases, including the subtotals for each of the invoice line numbers. (Hint: Modify the
query format used to produce the listing of customer purchases in Problem 18, delete the
INV_DATE column, and add the derived (computed) attribute LINE_UNITS * LINE_PRICE
to calculate the subtotals.)
FIGURE P7.29 Summary of Customer Purchases with Subtotals
SELECT INVOICE.CUS_CODE, INVOICE.INV_NUMBER, PRODUCT.P_DESCRIPT,
LINE.LINE_UNITS AS [Units Bought], LINE.LINE_PRICE AS [Unit Price],
LINE.LINE_UNITS*LINE.LINE_PRICE AS Subtotal
FROM CUSTOMER, INVOICE, LINE, PRODUCT
WHERE CUSTOMER.CUS_CODE = INVOICE.CUS_CODE
AND INVOICE.INV_NUMBER = LINE.INV_NUMBER
AND PRODUCT.P_CODE = LINE.P_CODE
ORDER BY INVOICE.CUS_CODE, INVOICE.INV_NUMBER, PRODUCT.P_DESCRIPT;
Chapter 7 An Introduction to Structured Query Language (SQL)
255
30. Modify the query used in Problem 29 to produce the summary shown in Figure P7.30.
FIGURE P7.30 Customer Purchase Summary
SELECT INVOICE.CUS_CODE, CUSTOMER.CUS_BALANCE,
Sum(LINE.LINE_UNITS*LINE.LINE_PRICE) AS [Total Purchases]
FROM CUSTOMER, INVOICE, LINE
WHERE INVOICE.INV_NUMBER = LINE.INV_NUMBER
AND CUSTOMER.CUS_CODE = INVOICE.CUS_CODE
GROUP BY INVOICE.CUS_CODE, CUSTOMER.CUS_BALANCE;
31. Modify the query in Problem 30 to include the number of individual product purchases made
by each customer. (In other words, if the customer’s invoice is based on three products, one
per LINE_NUMBER, you would count three product purchases. If you examine the original
invoice data, you will note that customer 10011 generated three invoices, which contained a
total of six lines, each representing a product purchase.) Your output values must match those
shown in Figure P7.31.
FIGURE P7.31 Customer Total Purchase Amounts and Number of Purchases
SELECT INVOICE.CUS_CODE, CUSTOMER.CUS_BALANCE,
Sum(LINE.LINE_UNITS*LINE.LINE_PRICE) AS [Total Purchases],
Count(*) AS [Number of Purchases]
FROM CUSTOMER, INVOICE, LINE
WHERE INVOICE.INV_NUMBER = LINE.INV_NUMBER
AND CUSTOMER.CUS_CODE = INVOICE.CUS_CODE
GROUP BY INVOICE.CUS_CODE, CUSTOMER.CUS_BALANCE;
Chapter 7 An Introduction to Structured Query Language (SQL)
256
32. Use a query to compute the average purchase amount per product made by each customer.
(Hint: Use the results of Problem 31 as the basis for this query.) Your output values must
match those shown in Figure P7.32. Note that the Average Purchase Amount is equal to the
Total Purchases divided by the Number of Purchases.
FIGURE P7.32 Average Purchase Amount by Customer
SELECT INVOICE.CUS_CODE, CUSTOMER.CUS_BALANCE,
Sum(LINE.LINE_UNITS*LINE.LINE_PRICE) AS [Total Purchases],
Count(*) AS [Number of Purchases],
AVG(LINE.LINE_UNITS*LINE.LINE_PRICE) AS [Average Purchase Amount]
FROM CUSTOMER, INVOICE, LINE
WHERE INVOICE.INV_NUMBER = LINE.INV_NUMBER
AND CUSTOMER.CUS_CODE = INVOICE.CUS_CODE
GROUP BY INVOICE.CUS_CODE, CUSTOMER.CUS_BALANCE;
33. Create a query to produce the total purchase per invoice, generating the results shown in
Figure P7.33. The Invoice Total is the sum of the product purchases in the LINE that
corresponds to the INVOICE.
FIGURE P7.33 Invoice Totals
SELECT LINE.INV_NUMBER,
Sum(LINE.LINE_UNITS*LINE.LINE_PRICE) AS [Invoice Total]
FROM LINE
GROUP BY LINE.INV_NUMBER;
Chapter 7 An Introduction to Structured Query Language (SQL)
257
34. Use a query to show the invoices and invoice totals as shown in Figure P7.34. (Hint: Group by
the CUS_CODE.)
FIGURE P7.34 Invoice Totals by Customer
SELECT CUS_CODE, LINE.INV_NUMBER AS INV_NUMVER,
Sum(LINE.LINE_UNITS*LINE.LINE_PRICE) AS [Invoice Total]
FROM INVOICE, LINE
WHERE INVOICE.INV_NUMBER = LINE.INV_NUMBER
GROUP BY CUS_CODE, LINE.INV_NUMBER;
35. Write a query to produce the number of invoices and the total purchase amounts by customer,
using the output shown in Figure P7.35 as your guide. (Compare this summary to the results
shown in Problem 34.)
FIGURE P7.35 Number of Invoices and Total Purchase Amounts by Customer
Note that a query may be used as the data source for another query. The following code is shown in
qryP7.35A in your Ch07_Saleco database. Note that the data source is qryP6-34.
SELECT CUS_CODE,
Count(INV_NUMBER) AS [Number of Invoices],
AVG([Invoice Total]) AS [Average Invoice Amount],
MAX([Invoice Total]) AS [Max Invoice Amount],
MIN([Invoice Total]) AS [Min Invoice Amount],
Sum([Invoice Total]) AS [Total Customer Purchases]
FROM [qryP7-34]
GROUP BY [qryP7-34].CUS_CODE;
Chapter 7 An Introduction to Structured Query Language (SQL)
258
Instead of using another query as your data source, you can also use an alias. The following code is
shown in Oracle format. You can also find the MS Access “alias” version in qryP7.35B in your
Ch07_SaleCo database.)
SELECT CUS_CODE,
COUNT(LINE.INV_NUMBER) AS [Number of Invoices],
AVG([Invoice Total]) AS [Average Invoice Amount],
MAX([Invoice Total]) AS [Max Invoice Amount],
MIN([Invoice Total]) AS [Min Invoice Amount],
Sum([Invoice Total]) AS [Total Customer Purchases]
FROM (SELECT CUS_CODE, LINE.INV_NUMBER AS INV_NUMBER,
Sum(LINE.LINE_UNITS*LINE.LINE_PRICE) AS [Invoice Total]
FROM INVOICE, LINE
WHERE INVOICE.INV_NUMBER = LINE.INV_NUMBER
GROUP BY CUS_CODE, LINE.INV_NUMBER)
GROUP BY CUS_CODE;
36. Using the query results in Problem 35 as your basis, write a query to generate the total
number of invoices, the invoice total for all of the invoices, the smallest invoice amount,
the largest invoice amount, and the average of all of the invoices. (Hint: Check the figure
output in Problem 35.) Your output must match Figure P7.36.
FIGURE P7.36 Number of Invoices, Invoice Totals, Minimum, Maximum, and
Average Sales
SELECT Count([qryP7-34].[INV_NUMBER]) AS [Total Invoices],
Sum([qryP7-34].[Invoice Total]) AS [Total Sales],
Min([qryP7-34].[Invoice Total]) AS [Minimum Sale],
Max([qryP7-34].[Invoice Total]) AS [Largest Sale],
Avg([qryP7-34].[Invoice Total]) AS [Average Sale]
FROM [qryP7-34];
Another Random Scribd Document
with Unrelated Content
Database Systems Design Implementation and Management 11th Edition Coronel Solutions Manual
My Palace.
built me a little palace,
Somewhere in the ether land,
Wherein my soul might revel
And rest at my command.
The spot, a royal summit,
I let my will select,
And Fancy came inspecting
With Thought, the architect.
We went down to the quarry
For the foundation rock,
And purchased hewn and polished
Love’s marble corner block.
For years we toiled together,
And one day warm and sweet
I woke and found my palace
Before me and complete.
It was a gorgeous building—
The window lights of red
Came from the sunset’s furnace,
Or Northern light instead.
Each peak, each tower and turret
The sunlight’s love had won,
And straight there came a voice
From heaven and said “well done.”
I planted a grove beyond it,
And hedged up the terraced yard,
And I dug a groove so a brooklet
Could play on the level sward.
I wanted a flower to cheer me,
And off on a breezy slope
I scattered the seed of roses
And the purple heliotrope.
I peopled the rooms with volumes
Of men with talents rare,
Who climbed upon Fame’s spire
And waved their banners there.
I purchased the costliest paintings,
And swung them from the walls;
And music, like harps of heaven,
Resounded throughout the halls.
I gave a royal banquet,
The nuptial feast was spread,
And then, when all was ready,
There Love and I were wed.
But when the guests departed,
A rap came on the door,
And a gaunt figure faced me
I ne’er had seen before.
“My name,” she said, “is Envy;
I wish to stop with you;
Your dwelling just completed,
The inmates must be few.”
Her breath, like fumes of sulphur,
Into my face was blown,
And like a demon’s curses
Was her departing tone.
The night came on, and fingers
Tapped on the beveled glass,
A face looked in the window
With eyes that shone like brass;
But Love beheld the visage,
And o’er the window drew
A shade that shut Suspicion
Forever from my view.
And then a pond’rous knocking
Bombarded at the door,
And like an earthquake’s tremor
Upheaved the palace floor.
I glanced into the key-hole,
And, like the brand of Cain,
I saw on Slander’s forehead
A dark and bloody stain.
I barred the palace entrance,
And turning in the hall
We faced another figure
More dreadful than them all;
He said: “My name is Ruin—
Unbidden here I stand,
To curse your happy homestead
And desolate your land.
“The lichen I have sprinkled
Upon your crumbling tower,
The ivy and the myrtle
Shall choke each blooming flower.”
And then he smote the castle,
It trembled to its base,
And fell? No, no—I shouted
And laughed out in his face:
“You can not wreck our palace,
Love is the corner stone,
And we are master workmen,”
I said, in jocund tone.
He seized his trailing garments,
Departed with a groan,
And love and I together
Were once more left alone.
Next day as they debated
What course to next pursue,
I heard a sweet voice calling—
Love said the tone he knew.
The step, low as a mother’s
Upon the nursery floor,
Was like advancing music
That halted at our door.
As when a fairy’s castle
Yields to a magic key,
Our door swung on the hinges
The guest was—Sympathy.
“Come in, our worthy sister,”
I heard Love then repeat;
“For happiness without you
Could never be complete.”
And while we sat together,
Weaving our garland sweet,
For many a bridal altar,
For many a burial sheet,
We heard another footstep;
And, like an angel sent,
There came and smiled upon us
The face we loved—Content.
The circle was completed—
My palace stands sublime
Still on that cloudland summit,
And laughs at threats of Time.
No curses thunder o’er us,
No heavy rains can fall;
For heaven’s open window
Slants sunshine over all.
Database Systems Design Implementation and Management 11th Edition Coronel Solutions Manual
Death of Summer.
UMMER’S dying, close the shutters,
Make the light subdued and sweet,
The last accent that she utters
I’ll record here at her feet.
See, the pulses quiver faintly,
But her heart, alas! ’tis still;
See how pale she lies and saintly,
Feel her hands, they’re white and chill.
Close the eyes made sad from weeping,
Smooth the tangles from her head,
Leave her like an angel sleeping,
Friends are here to view the dead.
See, the rose a tear is dropping
As she leans above her face,
At the door the lily stopping,
Finds her handkerchief of lace.
There the two like sisters sorrow,
As above the corse they bend,
Planning for the sad to-morrow—
For the burial of a friend.
Then the daisy from the mountain,
That in mourning shawl was dressed,
Brought a snowdrow from the fountain,
Lay it on the summer’s breast.
To the pillow crept the lilacs,
But the flowers at her throat
Were the heliotrope and smilax—
This was gained by casting vote—
And the jasmine sought her fingers,
While the fuschias kissed her hair;
At her lip a violet lingers
To deny them, who would dare?
Then the autumn’s sunny treasure
Came the sturdy golden rod,
For the coffin took the measure,
For the grave removed the sod.
Long and mournful the procession
That I watched across the hill,
For to you I’ll make confession,
Autumn doth my spirit kill.
Drives me from the scene of sadness
While on poison nature feeds;
Decks her out in robes of gladness
To conceal the heart that bleeds;
At the summer’s grave there lingers
None more sad to drop a tear
Than the friend whose trembling fingers
Write this in memoriam here.
Database Systems Design Implementation and Management 11th Edition Coronel Solutions Manual
Spring and Summer.
heard a footstep on the hill,
The little brook began to trill,
I looked—a sweet and childlike face,
Reflected like a blooming vase,
Was smiling from the water clear,
With buttercups behind her ear.
A flock of swallows hove in sight,
On came the summer clad in white,
With sunshine falling from her hair
Upon her shoulders white and bare,
And pressing through the tangled grass,
A daisy rose to watch her pass.
Database Systems Design Implementation and Management 11th Edition Coronel Solutions Manual
Under the Snow.
HAT have you hidden down under the snow,
So dear that you weep when the northern blasts blow?
Why your face pressed to the cold window pane,
Longing to mingle your tears with the rain—
Is there something down under the snow?
Is it only a blossom, a summer’s delight,
That is freezing and dying this cold, bitter night?
That is only a fancy, the floweret is warm,
And the drift has enfolded it safe from the storm—
Is there something yet under the snow?
Something near to the heart down under the snow,
That has robbed the wan cheek of its once carmine glow,
That has stolen the beam of the eye—tears instead
Bespeak how in anguish the sore heart hath bled
For a little child under the snow.
For a dear little prattler that littered the floor,
And laughed as he tumbled your work o’er and o’er
For a little gold head that made sunny the room,
Now bright’ning the darkness and chill of the tomb,
That is dreaming out under the snow.
Only resting awhile in garments all white,
Away from the blackness and sin of to-night;
Away from the vice and the wrong of the street,
Not heeding the song of the rain or the sleet,
Still sleeping down under the snow.
How many a mother her darling would lay
In the last, narrow home—hide her treasure away—
If only to know its soul was at rest
With an innocent heart in an innocent breast,
Far, far down under the snow!
Database Systems Design Implementation and Management 11th Edition Coronel Solutions Manual
The Prettiest Girl in Town.
AVE you e’er seen her, this beautiful girl
With that classical head and complexion of pearl?
So pale and enchanting that sometimes I deem
Her a sweet revelation as when in a dream,
Through wild variations of trouble and fear,
You suddenly feel that an angel is near.
Now guess, if you can, without half of that frown,
For to me she’s the prettiest girl in the town.
The poets all sing of these quaint Highland girls
With enchanting dimples and loose tangled curls;
Or they weave a love-tale from her budding lip’s glow
While chasing the reindeer o’er mountains of snow;
This is only the skill of a well tinctured pen,
Dipped in Romance’s cup for the praises of men,
Who value this maid in the coarse homespun gown
Something less than the prettiest girl in the town.
You must all have watched the calm light of her eyes,
And ethereal figure with heavy drawn sighs;
Pondered often in secret of some magic gift
To win you this face—so like a snowdrift—
I would whisper a secret: On Valentine’s day,
With Cupid commune in a sly, cunning way,
Else only in dreams she is thine; for a crown
Could not purchase the prettiest girl in the town.
Database Systems Design Implementation and Management 11th Edition Coronel Solutions Manual
Database Systems Design Implementation and Management 11th Edition Coronel Solutions Manual
I am Musing To-Night.
am musing to-night in the fire-light’s glow,
And watching the pictures that come and go;
Like dissolving views on a magic screen
Is the witchery of this changing scene;
Though half I’m dreaming, though half awake,
I fear to move lest the spell I break,
Lest my fairy castles will break and fall,
And down will tumble each beautiful wall.
Thus still in a stupor I sit and gaze
At the glowing embers and wanton blaze;
I am smiling at Fancy; she tries in vain
To lure me along with the mad’ning train
That follow her footsteps—that to her cling,
As flowers that garland the steps of spring;
In moody silence I sit apart,
Till memory conquers my sullen heart.
Sweet Memory! sprite of my golden past!
Your tinseled veil o’er me is cast;
Subdued I yield like one enchained,
And yet my freedom is only feigned;
Back through the aisles of years that are gone,
A willing captive you lead me on,
Where I gleaned unbidden the joys of youth
While the world was blossoming with love and truth.
Before my heart could interpret a sigh,
Or a tear-drop’s shadow creep into my eye,
Ere I’d missed from the circle of friendship’s chain
The link once lost that we ne’er regain,
The future to me was a vast expanse,
Its depth I could solve at a single glance,
Knew not of the troubles that torture the soul
Hidden away in its sober fold.
Yet, to-night, as I dream in the gathering gloom,
Only friends that are dear softly enter my room,
Those who gladdened my life in its season of pain,
Like a gleam of the sunshine along with the rain;
These, these are the guests that encircle my hearth,
Who come gliding like spirits back to the earth.
What communion we hold only those ever know
Who sit musing alone in the fire-light’s glow.
Database Systems Design Implementation and Management 11th Edition Coronel Solutions Manual
A Curl.
O-NIGHT, as I turned back the pages
Of a book Time had fingered before,
And whose leaves held the odor of ages,
And the imprints of much usage wore,
A little brown curl I discovered,
That fell from the book to the floor.
Had I sinned? Heaven grant me its pardon.
Did a lover’s sad tear the page spot?
Who pressed there that gem of the garden—
The sweet flower, “forget-me-not?”
It lay as if carved on a grave-stone,
And all of its sweetness forgot.
I held the curl up to the lamplight,
And watching the gleam of its gold,
There I heard with the rush of the midnight,
A sad little story it told;
But I promised the sacred old volume
Its secret I would not unfold.
But I would that the world knew its sorrow,
The story I must not reveal;
But go to your book case to-morrow.
And each to your own heart appeal;
And you’ll know why the tattered old volume
The little curl tries to conceal.
Database Systems Design Implementation and Management 11th Edition Coronel Solutions Manual
Database Systems Design Implementation and Management 11th Edition Coronel Solutions Manual
Somebody’s Face.
TO M. A. B.
HE blossoms are gone from the garden,
But ’tis not of them I would speak;
I want a sweet rose for my verses
Like one that’s in somebody’s cheek.
A red rose to kiss and to fondle,
Whose leaves will not wither or die—
To gladden each moment and banish
The winter thoughts out of the sky.
I want a low ripple of music
To flow through these lines of my choice,
Like a zephyr that moved through the summer,
Now dwelling in somebody’s voice;
A song that will be full of fragrance
So sweet that its magic of words
Will bring back the balm of the June time,
Its memories glad, and the birds.
The skies are so sunless and dreary,
Unless I can find a deep blue
To mix with the clouds of November
They’ll still wear the dark, sober hue;
But memory shows a bright heaven
Reflected in somebody’s eye,
And, thinking to-day of its beauty,
The grey becomes blue in the sky.
My dear little friend of the summer,
Did you think in the meshes of song
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
More than just a book-buying platform, we strive to be a bridge
connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.
Join us on a journey of knowledge exploration, passion nurturing, and
personal growth every day!
testbankfan.com

More Related Content

Similar to Database Systems Design Implementation and Management 11th Edition Coronel Solutions Manual (20)

DOC
SQLQueries
karunakar81987
 
PDF
Modern Database Management 11th Edition Hoffer Solutions Manual
bardhdinci22
 
PDF
Top 50 SQL Interview Questions and Answer.pdf
Rajkumar751652
 
PPTX
Sql
Mahfuz1061
 
PDF
Database Systems Design Implementation and Management 11th Edition Coronel Te...
haeriforisr6
 
PDF
Database Systems Design Implementation and Management 11th Edition Coronel Te...
farmerposhia42
 
PDF
Essentials of Database Management 1st Edition Hoffer Solutions Manual
lelanaarshat
 
PPT
Unit-3-SQL-part1.ppt
vipinpanicker2
 
PDF
1Z0-061 Oracle Database 12c: SQL Fundamentals
Lydi00147
 
PPTX
SQL.pptx
AmitDas125851
 
DOC
Ora faq
vishpoola
 
DOC
Ora faq
vishpoola
 
PPT
chap 7.ppt(sql).ppt
arjun431527
 
PDF
Modern Database Management 11th Edition Hoffer Solutions Manual
wennvoutaz13
 
PDF
Database Systems Design Implementation and Management 11th Edition Coronel Te...
sokktakei
 
PPT
Chapt7.ppt
ImXaib
 
PDF
Modern Database Management 11th Edition Hoffer Solutions Manual
sxofmpd282
 
PPTX
SQL.pptx
SAIFKHAN41507
 
PDF
Essentials of Database Management 1st Edition Hoffer Solutions Manual
saxlinsitou55
 
PPTX
Ebook3
kaashiv1
 
SQLQueries
karunakar81987
 
Modern Database Management 11th Edition Hoffer Solutions Manual
bardhdinci22
 
Top 50 SQL Interview Questions and Answer.pdf
Rajkumar751652
 
Database Systems Design Implementation and Management 11th Edition Coronel Te...
haeriforisr6
 
Database Systems Design Implementation and Management 11th Edition Coronel Te...
farmerposhia42
 
Essentials of Database Management 1st Edition Hoffer Solutions Manual
lelanaarshat
 
Unit-3-SQL-part1.ppt
vipinpanicker2
 
1Z0-061 Oracle Database 12c: SQL Fundamentals
Lydi00147
 
SQL.pptx
AmitDas125851
 
Ora faq
vishpoola
 
Ora faq
vishpoola
 
chap 7.ppt(sql).ppt
arjun431527
 
Modern Database Management 11th Edition Hoffer Solutions Manual
wennvoutaz13
 
Database Systems Design Implementation and Management 11th Edition Coronel Te...
sokktakei
 
Chapt7.ppt
ImXaib
 
Modern Database Management 11th Edition Hoffer Solutions Manual
sxofmpd282
 
SQL.pptx
SAIFKHAN41507
 
Essentials of Database Management 1st Edition Hoffer Solutions Manual
saxlinsitou55
 
Ebook3
kaashiv1
 

Recently uploaded (20)

PDF
Introduction presentation of the patentbutler tool
MIPLM
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PPTX
Difference between write and update in odoo 18
Celine George
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
PDF
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
PDF
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PPTX
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
PDF
Council of Chalcedon Re-Examined
Smiling Lungs
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
epi editorial commitee meeting presentation
MIPLM
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
Introduction to Indian Writing in English
Trushali Dodiya
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Introduction presentation of the patentbutler tool
MIPLM
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
Difference between write and update in odoo 18
Celine George
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
Council of Chalcedon Re-Examined
Smiling Lungs
 
Horarios de distribución de agua en julio
pegazohn1978
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
epi editorial commitee meeting presentation
MIPLM
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Introduction to Indian Writing in English
Trushali Dodiya
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Ad

Database Systems Design Implementation and Management 11th Edition Coronel Solutions Manual

  • 1. Visit https://testbankfan.com to download the full version and browse more test banks or solution manuals Database Systems Design Implementation and Management 11th Edition Coronel Solutions Manual _____ Press the link below to begin your download _____ https://testbankfan.com/product/database-systems-design- implementation-and-management-11th-edition-coronel- solutions-manual/ Access testbankfan.com now to download high-quality test banks or solution manuals
  • 2. Here are some recommended products for you. Click the link to download, or explore more at testbankfan.com Database Systems Design Implementation and Management 11th Edition Coronel Test Bank https://testbankfan.com/product/database-systems-design- implementation-and-management-11th-edition-coronel-test-bank/ Database Systems Design Implementation and Management 12th Edition Coronel Solutions Manual https://testbankfan.com/product/database-systems-design- implementation-and-management-12th-edition-coronel-solutions-manual/ Database Systems Design Implementation And Management 13th Edition Coronel Solutions Manual https://testbankfan.com/product/database-systems-design- implementation-and-management-13th-edition-coronel-solutions-manual/ Business Law in Canada Canadian Edition Canadian 10th Edition Yates Test Bank https://testbankfan.com/product/business-law-in-canada-canadian- edition-canadian-10th-edition-yates-test-bank/
  • 3. Modern Advanced Accounting in Canada Canadian 7th Edition Hilton Solutions Manual https://testbankfan.com/product/modern-advanced-accounting-in-canada- canadian-7th-edition-hilton-solutions-manual/ Information Systems A Managers Guide to Harnessing Technology 1st Edition Gallaugher Test Bank https://testbankfan.com/product/information-systems-a-managers-guide- to-harnessing-technology-1st-edition-gallaugher-test-bank/ Organizations Behavior Structure Processes 14th Edition Gibson Test Bank https://testbankfan.com/product/organizations-behavior-structure- processes-14th-edition-gibson-test-bank/ Finite Mathematics and Its Applications 12th Edition Goldstein Solutions Manual https://testbankfan.com/product/finite-mathematics-and-its- applications-12th-edition-goldstein-solutions-manual/ Human Resource Information Systems 3rd Edition Kavanagh Test Bank https://testbankfan.com/product/human-resource-information- systems-3rd-edition-kavanagh-test-bank/
  • 4. Chemistry An Atoms First Approach 2nd Edition Zumdahl Solutions Manual https://testbankfan.com/product/chemistry-an-atoms-first-approach-2nd- edition-zumdahl-solutions-manual/
  • 5. Chapter 7 An Introduction to Structured Query Language (SQL) 239 Chapter 7 Introduction to Structured Query Language (SQL) NOTE Several points are worth emphasizing: • We have provided the SQL scripts for both chapters 7 and 8. These scripts are intended to facilitate the flow of the material presented to the class. However, given the comments made by our students, the scripts should not replace the manual typing of the SQL commands by students. Some students learn SQL better when they have a chance to type their own commands and get the feedback provided by their errors. We recommend that the students use their lab time to practice the commands manually. • Because this chapter focuses on learning SQL, we recommend that you use the Microsoft Access SQL window to type SQL queries. Using this approach, you will be able to demonstrate the interoperability of standard SQL. For example, you can cut and paste the same SQL command from the SQL query window in Microsoft Access, to Oracle SQL * Plus and to MS SQL Query Analyzer. This approach achieves two objectives: ➢ It demonstrates that adhering to the SQL standard means that most of the SQL code will be portable among DBMSes. ➢ It also demonstrates that even a widely accepted SQL standard is sometimes implemented with slight distinctions by different vendors. For example, the treatment of date formats in Microsoft Access and Oracle is slightly different. Answers to Review Questions 1. In a SELECT query, what is the difference between a WHERE clause and a HAVING clause? Both a WHERE clause and a HAVING clause can be used to eliminate rows from the results of a query. The differences are 1) the WHERE clause eliminates rows before any grouping for aggregate functions occurs while the HAVING clause eliminates groups after the grouping has been done, and 2) the WHERE clause cannot contain an aggregate function but the HAVING clause can. 2. Explain why the following command would create an error, and what changes could be made to fix the error. SELECT V_CODE, SUM(P_QOH) FROM PRODUCT; The command would generate an error because an aggregate function is applied to the P_QOH attribute but V_CODE is neither in an aggregate function or in a GROUP BY. This can be fixed by either 1) placing V_CODE in an appropriate aggregate function based on the data that is being requested by the user, 2) adding a GROUP BY clause to group by values of V_CODE (i.e. GROUP BY V_CODE), 3) removing the V_CODE attribute from the SELECT clause, or 4) removing the Sum aggregate function from P_QOH. Which of these solutions is most appropriate depends on the question that the query was intended to answer.
  • 6. Chapter 7 An Introduction to Structured Query Language (SQL) 240 3. What type of integrity is enforced when a primary key is declared? Creating a primary key constraint enforces entity integrity (i.e. no part of the primary key can contain a null and the primary key values must be unique). 4. Explain why it might be more appropriate to declare an attribute that contains only digits as a character data type instead of a numeric data type. An attribute that contains only digits may be properly defined as character data when the values are nominal; that is, the values do not have numerical significance but serve only as labels such as ZIP codes and telephone numbers. One easy test is to consider whether or not a leading zero should be retained. For the ZIP code 03133, the leading zero should be retained; therefore, it is appropriate to define it as character data. For the quantity on hand of 120, we would not expect to retain a leading zero such as 0120; therefore, it is appropriate to define the quantity on hand as a numeric data type. 5. What is the difference between a column constraint and a table constraint? A column constraint can refer to only the attribute with which it is specified. A table constraint can refer to any attributes in the table. 6. What are “referential constraint actions”? Referential constraint actions, such as ON DELETE CASCADE, are default actions that the DBMS should take when a DML command would result in a referential integrity constraint violation. Without referential constraint actions, DML commands that would result in a violation of referential integrity will fail with an error indicating that the referential integrity constrain cannot be violated. Referential constraint actions can allow the DML command to successfully complete while making the designated changes to the related records to maintain referential integrity. 7. Rewrite the following WHERE clause without the use of the IN special operator. WHERE V_STATE IN (‘TN’, ‘FL’, ‘GA’) WHERE V_STATE = 'TN' OR V_STATE = 'FL' OR V_STATE = 'GA' Notice that each criteria must be complete (i.e. attribute-operator-value). 8. Explain the difference between an ORDER BY clause and a GROUP BY clause. An ORDER BY clause has no impact on which rows are returned by the query, it simply sorts those rows into the specified order. A GROUP BY clause does impact the rows that are returned by the query. A GROUP BY clause gathers rows into collections that can be acted on by aggregate functions. 9. Explain why the two following commands produce different results. SELECT DISTINCT COUNT (V_CODE) FROM PRODUCT;
  • 7. Chapter 7 An Introduction to Structured Query Language (SQL) 241 SELECT COUNT (DISTINCT V_CODE) FROM PRODUCT; The difference is in the order of operations. The first command executes the Count function to count the number of values in V_CODE (say the count returns "14" for example) including duplicate values, and then the Distinct keyword only allows one count of that value to be displayed (only one row with the value "14" appears as the result). The second command applies the Distinct keyword to the V_CODEs before the count is taken so only unique values are counted. 10. What is the difference between the COUNT aggregate function and the SUM aggregate function? COUNT returns the number of values without regard to what the values are. SUM adds the values together and can only be applied to numeric values. 11. Explain why it would be preferable to use a DATE data type to store date data instead of a character data type. The DATE data type uses numeric values based on the Julian calendar to store dates. This makes date arithmetic such as adding and subtracting days or fractions of days possible (as well as numerous special date-oriented functions discussed in the next chapter!). 12. What is a recursive join? A recursive join is a join in which a table is joined to itself. Problem Solutions O n l i n e C o n t e n t Problems 1 – 25 are based on the Ch07_ConstructCo database located www.cengagebrain.com. This database is stored in Microsoft Access format. The website provides Oracle, MySQL, and MS SQL Server script files. The Ch07_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 Ch07_ConstructCo database are shown in Figure P7.1. Figure P7.1 Structure and contents of the Ch07_ConstructCo database
  • 8. Chapter 7 An Introduction to Structured Query Language (SQL) 242 Note that the ASSIGNMENT table in Figure P7.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. And, naturally, the employee primary job assignment might change, so the ASSIGN_JOB is 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 Ch07_ConstructCo database shown in Figure P7.1, use SQL commands to answer Problems 1–25. 1. Write the SQL code that will create the table structure for a table named EMP_1. This table is a subset of the EMPLOYEE table. The basic EMP_1 table structure is summarized in the table below. (Note that the JOB_CODE is the FK to JOB.)
  • 9. Chapter 7 An Introduction to Structured Query Language (SQL) 243 ATTRIBUTE (FIELD) NAME DATA DECLARATION EMP_NUM CHAR(3) EMP_LNAME VARCHAR(15) EMP_FNAME VARCHAR(15) EMP_INITIAL CHAR(1) EMP_HIREDATE DATE JOB_CODE CHAR(3) CREATE TABLE EMP_1 ( EMP_NUM CHAR(3) PRIMARY KEY, EMP_LNAME VARCHAR(15) NOT NULL, EMP_FNAME VARCHAR(15) NOT NULL, EMP_INITIAL CHAR(1), EMP_HIREDATE DATE, JOB_CODE CHAR(3), FOREIGN KEY (JOB_CODE) REFERENCES JOB); NOTE We have already provided the EMP_1 table for you. If you try to run the preceding query, you will get an error message because the EMP_1 table already exits. 2. Having created the table structure in Problem 1, write the SQL code to enter the first two rows for the table shown in Figure P7.2. Figure P7.2 The contents of the EMP_1 table INSERT INTO EMP_1 VALUES (‘101’, ‘News’, ‘John’, ‘G’, ’08-Nov-00’, ‘502’); INSERT INTO EMP_1 VALUES (‘102’, ‘Senior’, ‘David’, ‘H’, ’12-Jul-89’, ‘501’); 3. Assuming the data shown in the EMP_1 table have been entered, write the SQL code that will list all attributes for a job code of 502. SELECT * FROM EMP_1 WHERE JOB_CODE = ‘502’;
  • 10. Chapter 7 An Introduction to Structured Query Language (SQL) 244 4. Write the SQL code that will save the changes made to the EMP_1 table. COMMIT; 5. Write the SQL code to change the job code to 501 for the person whose employee number (EMP_NUM) is 107. After you have completed the task, examine the results, and then reset the job code to its original value. UPDATE EMP_1 SET JOB_CODE = ‘501’ WHERE EMP_NUM = ‘107’; To see the changes: SELECT * FROM EMP_1 WHERE EMP_NUM = ‘107’; To reset, use ROLLBACK; 6. Write the SQL code to delete the row for the person named William Smithfield, who was hired on June 22, 2004, and whose job code classification is 500. (Hint: Use logical operators to include all of the information given in this problem.) DELETE FROM EMP_1 WHERE EMP_LNAME = 'Smithfield' AND EMP_FNAME = 'William' AND EMP_HIREDATE = '22-June-04' AND JOB_CODE = '500'; 7. Write the SQL code that will restore the data to its original status; that is, the table should contain the data that existed before you made the changes in Problems 5 and 6. ROLLBACK;
  • 11. Chapter 7 An Introduction to Structured Query Language (SQL) 245 8. Write the SQL code to create a copy of EMP_1, naming the copy EMP_2. Then write the SQL code that will add the attributes EMP_PCT and PROJ_NUM to its structure. The EMP_PCT is the bonus percentage to be paid to each employee. The new attribute characteristics are: EMP_PCTNUMBER(4,2) PROJ_NUMCHAR(3) (Note: If your SQL implementation allows it, you may use DECIMAL(4,2) rather than NUMBER(4,2).) There are two way to get this job done. The two possible solutions are shown next. Solution A: CREATE TABLE EMP_2 ( EMP_NUM CHAR(3) NOT NULL UNIQUE, EMP_LNAME VARCHAR(15) NOT NULL, EMP_FNAME VARCHAR(15) NOT NULL, EMP_INITIAL CHAR(1), EMP_HIREDATE DATE NOT NULL, JOB_CODE CHAR(3) NOT NULL, PRIMARY KEY (EMP_NUM), FOREIGN KEY (JOB_CODE) REFERENCES JOB); INSERT INTO EMP_2 SELECT * FROM EMP_1; ALTER TABLE EMP_2 ADD (EMP_PCT NUMBER (4,2)), ADD (PROJ_NUM CHAR(3)); Solution B: CREATE TABLE EMP_2 AS SELECT * FROM EMP_1; ALTER TABLE EMP_2 ADD (EMP_PCT NUMBER (4,2)), ADD (PROJ_NUM CHAR(3)); 9. Write the SQL code to change the EMP_PCT value to 3.85 for the person whose employee number (EMP_NUM) is 103. Next, write the SQL command sequences to change the EMP_PCT values as shown in Figure P7.9.
  • 12. Chapter 7 An Introduction to Structured Query Language (SQL) 246 Figure P7.9 The contents of the EMP_2 table UPDATE EMP_2 SET EMP_PCT = 3.85 WHERE EMP_NUM = '103'; To enter the remaining EMP_PCT values, use the following SQL statements: UPDATEEMP_2 SET EMP_PCT = 5.00 WHERE EMP_NUM = ‘101’; UPDATEEMP_2 SET EMP_PCT = 8.00 WHERE EMP_NUM = ‘102’; Follow this format for the remaining rows. 10. Using a single command sequence, write the SQL code that will change the project number (PROJ_NUM) to 18 for all employees whose job classification (JOB_CODE) is 500. UPDATE EMP_2 SET PROJ_NUM = '18' WHERE JOB_CODE = '500'; 11. Using a single command sequence, write the SQL code that will change the project number (PROJ_NUM) to 25 for all employees whose job classification (JOB_CODE) is 502 or higher. When you finish Problems 10 and 11, the EMP_2 table will contain the data shown in Figure P7.11. (You may assume that the table has been saved again at this point.)
  • 13. Chapter 7 An Introduction to Structured Query Language (SQL) 247 Figure P7.11 The EMP_2 table contents after the modification UPDATE EMP_2 SET PROJ_NUM = '25' WHERE JOB_CODE > = '502' 12. Write the SQL code that will change the PROJ_NUM to 14 for those employees who were hired before January 1, 1994 and whose job code is at least 501. (You may assume that the table will be restored to its condition preceding this question.) UPDATE EMP_2 SET PROJ_NUM = '14' WHERE EMP_HIREDATE <= ' 01-Jan-94' AND JOB_CODE >= '501'; 13. Write the two SQL command sequences required to: There are many ways to accomplish both tasks. We are illustrating the shortest way to do the job next. a. Create a temporary table named TEMP_1 whose structure is composed of the EMP_2 attributes EMP_NUM and EMP_PCT. The SQL code shown in problem 13b contains the solution for problem 13a. b. Copy the matching EMP_2 values into the TEMP_1 table. CREATE TABLE TEMP_1 AS SELECT EMP_NUM, EMP_PCT FROM EMP_2; An alternate way would be to create the table and then, use an INSERT with a sub-select to populate the rows. CREATE TABLE TEMP_1 AS ( EMP_NUM CHAR(3), EMP_PCT NUMBER(4,2)); INSERT INTO TEMP_1 SELECT EMP_NUM, EMP_PCT FROM EMP_2;
  • 14. Chapter 7 An Introduction to Structured Query Language (SQL) 248 14. Write the SQL command that will delete the newly created TEMP_1 table from the database. DROP TABLE TEMP_1; 15. Write the SQL code required to list all employees whose last names start with Smith. In other words, the rows for both Smith and Smithfield should be included in the listing. Assume case sensitivity. SELECT * FROM EMP_2 WHERE EMP_LNAME LIKE 'Smith%'; 16. Using the EMPLOYEE, JOB, and PROJECT tables in the Ch07_ConstructCo database (see Figure P7.1), write the SQL code that will produce the results shown in Figure P7.16. Figure P7.16 The query results for Problem 16 SELECT PROJ_NAME, PROJ_VALUE, PROJ_BALANCE, EMPLOYEE.EMP_LNAME, EMP_FNAME, EMP_INITIAL, EMPLOYEE.JOB_CODE, JOB.JOB_DESCRIPTION, JOB.JOB_CHG_HOUR FROM PROJECT, EMPLOYEE, JOB WHERE EMPLOYEE.EMP_NUM = PROJECT.EMP_NUM AND JOB.JOB_CODE = EMPLOYEE.JOB_CODE; 17. Write the SQL code that will produce a virtual table named REP_1. The virtual table should contain the same information that was shown in Problem 16. CREATE VIEW REP_1 AS SELECT PROJ_NAME, PROJ_VALUE, PROJ_BALANCE, EMPLOYEE.EMP_LNAME, EMP_FNAME, EMP_INITIAL, EMPLOYEE.JOB_CODE, JOB.JOB_DESCRIPTION, JOB.JOB_CHG_HOUR FROM PROJECT, EMPLOYEE, JOB WHERE EMPLOYEE.EMP_NUM = PROJECT.EMP_NUM AND JOB.JOB_CODE = EMPLOYEE.JOB_CODE;
  • 15. Chapter 7 An Introduction to Structured Query Language (SQL) 249 18. Write the SQL code to find the average bonus percentage in the EMP_2 table you created in Problem 8. SELECT AVG(EMP_PCT) FROM EMP_2; 19. Write the SQL code that will produce a listing for the data in the EMP_2 table in ascending order by the bonus percentage. SELECT * FROM EMP_2 ORDER BY EMP_PCT; 20. Write the SQL code that will list only the distinct project numbers found in the EMP_2 table. SELECT DISTINTC PROJ_NUM FROM EMP_2; 21. Write the SQL code to calculate the ASSIGN_CHARGE values in the ASSIGNMENT table in the Ch07_ConstructCo database. (See Figure P7.1.) Note that ASSIGN_CHARGE is a derived attribute that is calculated by multiplying ASSIGN_CHG_HR by ASSIGN_HOURS. UPDATE ASSIGNMENT SET ASSIGN_CHARGE = ASSIGN_CHG_HR * ASSIGN_HOURS; 22. 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. The results of running that query are shown in Figure P7.22. Figure P7.22 Total hours and charges by employee
  • 16. Chapter 7 An Introduction to Structured Query Language (SQL) 250 SELECT ASSIGNMENT.EMP_NUM, EMPLOYEE.EMP_LNAME, Sum(ASSIGNMENT.ASSIGN_HOURS) AS SumOfASSIGN_HOURS, Sum(ASSIGNMENT.ASSIGN_CHARGE) AS SumOfASSIGN_CHARGE FROM EMPLOYEE, ASSIGNMENT WHERE EMPLOYEE.EMP_NUM = ASSIGNMENT.EMP_NUM GROUP BY ASSIGNMENT.EMP_NUM, EMPLOYEE.EMP_LNAME; 23. Write a query to produce the total number of hours and charges for each of the projects represented in the ASSIGNMENT table. The output is shown in Figure P7.23. Figure P7.23 Total hour and charges by project SELECT ASSIGNMENT.PROJ_NUM, Sum(ASSIGNMENT.ASSIGN_HOURS) AS SumOfASSIGN_HOURS, Sum(ASSIGNMENT.ASSIGN_CHARGE) AS SumOfASSIGN_CHARGE FROM ASSIGNMENT GROUP BY ASSIGNMENT.PROJ_NUM 24. 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.24. (Hint: This is a nested query. If you use Microsoft Access, you can generate the result by using the query output shown in Figure P7.22 as the basis for the query that will produce the output shown in Figure P7.24.) Figure P7.24 Total hours and charges, all employees Solution A: SELECT Sum(SumOfASSIGN_HOURS) AS SumOfASSIGN_HOURS, Sum(SumOfASSIGN_CHARGE) AS SumOfASSIGN_CHARGE FROM Q23; or
  • 17. Chapter 7 An Introduction to Structured Query Language (SQL) 251 SELECT Sum(SumOfASSIGN_HOURS) AS SumOfASSIGN_HOURS, Sum(SumOfASSIGN_CHARGE as SumOfASSIGN_CHARGE FROM (SELECT ASSIGNMENT.PROJ_NUM, Sum(ASSIGNMENT.ASSIGN_HOURS) AS SumOfASSIGN_HOURS, Sum(ASSIGNMENT.ASSIGN_CHARGE) AS SumOfASSIGN_CHARGE FROM ASSIGNMENT GROUP BY ASSIGNMENT.PROJ_NUM ); Solution B: SELECT Sum(SumOfASSIGN_HOURS) AS SumOfASSIGN_HOURS, Sum(SumOfASSIGN_CHARGE) AS SumOfASSIGN_CHARGE FROM Q22; or SELECT Sum(SumOfASSIGN_HOURS) AS SumOfASSIGN_HOURS, Sum(SumOfASSIGN_CHARGE) AS SumOfASSIGN_CHARGE FROM (SELECT ASSIGNMENT.EMP_NUM, EMPLOYEE.EMP_LNAME, Sum(ASSIGNMENT.ASSIGN_HOURS) AS SumOfASSIGN_HOURS, Sum(ASSIGNMENT.ASSIGN_CHARGE) AS SumOfASSIGN_CHARGE FROM EMPLOYEE, ASSIGNMENT WHERE EMPLOYEE.EMP_NUM = ASSIGNMENT.EMP_NUM GROUP BY ASSIGNMENT.EMP_NUM, EMPLOYEE.EMP_LNAME );
  • 18. Chapter 7 An Introduction to Structured Query Language (SQL) 252 25. Write the SQL code to generate the total hours worked and the total charges made to all projects. The results should be the same as those shown in Figure P7.24. (Hint: This is a nested query. If you use Microsoft Access, you can generate the result by using the query output shown in Figure P7.23 as the basis for this query.) SELECT Sum(SumOfASSIGN_HOURS) AS SumOfASSIGN_HOURS, Sum(SumOfASSIGN_CHARGE) AS SumOfASSIGN_CHARGE FROM Q23; or SELECT Sum(SumOfASSIGN_HOURS) AS SumOfASSIGN_HOURS, Sum(SumOfASSIGN_CHARGE as SumOfASSIGN_CHARGE FROM (SELECT ASSIGNMENT.PROJ_NUM, Sum(ASSIGNMENT.ASSIGN_HOURS) AS SumOfASSIGN_HOURS, Sum(ASSIGNMENT.ASSIGN_CHARGE) AS SumOfASSIGN_CHARGE FROM ASSIGNMENT GROUP BY ASSIGNMENT.PROJ_NUM ); O n l i n e C o n t e n t Problems 26−43 are based on the Ch07_SaleCo database, which is available at www.cengagebrain.com. This database is stored in Microsoft Access format. Oracle, MySQL and MS SQL Server script files are available at www.cengagebrain.com. The structure and contents of the Ch07_SaleCo database are shown in Figure P7.26. Use this database to answer the following problems. Save each query as QXX, where XX is the problem number. 26. Write a query to count the number of invoices. SELECT COUNT(*) FROM INVOICE; 27. Write a query to count the number of customers with a customer balance over $500. SELECT COUNT(*) FROM CUSTOMER WHERE CUS_BALANCE >500;
  • 19. Chapter 7 An Introduction to Structured Query Language (SQL) 253 28. Generate a listing of all purchases made by the customers, using the output shown in Figure P7.28 as your guide. (Hint: Use the ORDER BY clause to order the resulting rows as shown in Figure P7.28) FIGURE P7.28 List of Customer Purchases SELECT INVOICE.CUS_CODE, INVOICE.INV_NUMBER, INVOICE.INV_DATE, PRODUCT.P_DESCRIPT, LINE.LINE_UNITS, LINE.LINE_PRICE FROM CUSTOMER, INVOICE, LINE, PRODUCT WHERE CUSTOMER.CUS_CODE = INVOICE.CUS_CODE AND INVOICE.INV_NUMBER = LINE.INV_NUMBER AND PRODUCT.P_CODE = LINE.P_CODE ORDER BY INVOICE.CUS_CODE, INVOICE.INV_NUMBER, PRODUCT.P_DESCRIPT;
  • 20. Chapter 7 An Introduction to Structured Query Language (SQL) 254 29. Using the output shown in Figure P7.29 as your guide, generate the listing of customer purchases, including the subtotals for each of the invoice line numbers. (Hint: Modify the query format used to produce the listing of customer purchases in Problem 18, delete the INV_DATE column, and add the derived (computed) attribute LINE_UNITS * LINE_PRICE to calculate the subtotals.) FIGURE P7.29 Summary of Customer Purchases with Subtotals SELECT INVOICE.CUS_CODE, INVOICE.INV_NUMBER, PRODUCT.P_DESCRIPT, LINE.LINE_UNITS AS [Units Bought], LINE.LINE_PRICE AS [Unit Price], LINE.LINE_UNITS*LINE.LINE_PRICE AS Subtotal FROM CUSTOMER, INVOICE, LINE, PRODUCT WHERE CUSTOMER.CUS_CODE = INVOICE.CUS_CODE AND INVOICE.INV_NUMBER = LINE.INV_NUMBER AND PRODUCT.P_CODE = LINE.P_CODE ORDER BY INVOICE.CUS_CODE, INVOICE.INV_NUMBER, PRODUCT.P_DESCRIPT;
  • 21. Chapter 7 An Introduction to Structured Query Language (SQL) 255 30. Modify the query used in Problem 29 to produce the summary shown in Figure P7.30. FIGURE P7.30 Customer Purchase Summary SELECT INVOICE.CUS_CODE, CUSTOMER.CUS_BALANCE, Sum(LINE.LINE_UNITS*LINE.LINE_PRICE) AS [Total Purchases] FROM CUSTOMER, INVOICE, LINE WHERE INVOICE.INV_NUMBER = LINE.INV_NUMBER AND CUSTOMER.CUS_CODE = INVOICE.CUS_CODE GROUP BY INVOICE.CUS_CODE, CUSTOMER.CUS_BALANCE; 31. Modify the query in Problem 30 to include the number of individual product purchases made by each customer. (In other words, if the customer’s invoice is based on three products, one per LINE_NUMBER, you would count three product purchases. If you examine the original invoice data, you will note that customer 10011 generated three invoices, which contained a total of six lines, each representing a product purchase.) Your output values must match those shown in Figure P7.31. FIGURE P7.31 Customer Total Purchase Amounts and Number of Purchases SELECT INVOICE.CUS_CODE, CUSTOMER.CUS_BALANCE, Sum(LINE.LINE_UNITS*LINE.LINE_PRICE) AS [Total Purchases], Count(*) AS [Number of Purchases] FROM CUSTOMER, INVOICE, LINE WHERE INVOICE.INV_NUMBER = LINE.INV_NUMBER AND CUSTOMER.CUS_CODE = INVOICE.CUS_CODE GROUP BY INVOICE.CUS_CODE, CUSTOMER.CUS_BALANCE;
  • 22. Chapter 7 An Introduction to Structured Query Language (SQL) 256 32. Use a query to compute the average purchase amount per product made by each customer. (Hint: Use the results of Problem 31 as the basis for this query.) Your output values must match those shown in Figure P7.32. Note that the Average Purchase Amount is equal to the Total Purchases divided by the Number of Purchases. FIGURE P7.32 Average Purchase Amount by Customer SELECT INVOICE.CUS_CODE, CUSTOMER.CUS_BALANCE, Sum(LINE.LINE_UNITS*LINE.LINE_PRICE) AS [Total Purchases], Count(*) AS [Number of Purchases], AVG(LINE.LINE_UNITS*LINE.LINE_PRICE) AS [Average Purchase Amount] FROM CUSTOMER, INVOICE, LINE WHERE INVOICE.INV_NUMBER = LINE.INV_NUMBER AND CUSTOMER.CUS_CODE = INVOICE.CUS_CODE GROUP BY INVOICE.CUS_CODE, CUSTOMER.CUS_BALANCE; 33. Create a query to produce the total purchase per invoice, generating the results shown in Figure P7.33. The Invoice Total is the sum of the product purchases in the LINE that corresponds to the INVOICE. FIGURE P7.33 Invoice Totals SELECT LINE.INV_NUMBER, Sum(LINE.LINE_UNITS*LINE.LINE_PRICE) AS [Invoice Total] FROM LINE GROUP BY LINE.INV_NUMBER;
  • 23. Chapter 7 An Introduction to Structured Query Language (SQL) 257 34. Use a query to show the invoices and invoice totals as shown in Figure P7.34. (Hint: Group by the CUS_CODE.) FIGURE P7.34 Invoice Totals by Customer SELECT CUS_CODE, LINE.INV_NUMBER AS INV_NUMVER, Sum(LINE.LINE_UNITS*LINE.LINE_PRICE) AS [Invoice Total] FROM INVOICE, LINE WHERE INVOICE.INV_NUMBER = LINE.INV_NUMBER GROUP BY CUS_CODE, LINE.INV_NUMBER; 35. Write a query to produce the number of invoices and the total purchase amounts by customer, using the output shown in Figure P7.35 as your guide. (Compare this summary to the results shown in Problem 34.) FIGURE P7.35 Number of Invoices and Total Purchase Amounts by Customer Note that a query may be used as the data source for another query. The following code is shown in qryP7.35A in your Ch07_Saleco database. Note that the data source is qryP6-34. SELECT CUS_CODE, Count(INV_NUMBER) AS [Number of Invoices], AVG([Invoice Total]) AS [Average Invoice Amount], MAX([Invoice Total]) AS [Max Invoice Amount], MIN([Invoice Total]) AS [Min Invoice Amount], Sum([Invoice Total]) AS [Total Customer Purchases] FROM [qryP7-34] GROUP BY [qryP7-34].CUS_CODE;
  • 24. Chapter 7 An Introduction to Structured Query Language (SQL) 258 Instead of using another query as your data source, you can also use an alias. The following code is shown in Oracle format. You can also find the MS Access “alias” version in qryP7.35B in your Ch07_SaleCo database.) SELECT CUS_CODE, COUNT(LINE.INV_NUMBER) AS [Number of Invoices], AVG([Invoice Total]) AS [Average Invoice Amount], MAX([Invoice Total]) AS [Max Invoice Amount], MIN([Invoice Total]) AS [Min Invoice Amount], Sum([Invoice Total]) AS [Total Customer Purchases] FROM (SELECT CUS_CODE, LINE.INV_NUMBER AS INV_NUMBER, Sum(LINE.LINE_UNITS*LINE.LINE_PRICE) AS [Invoice Total] FROM INVOICE, LINE WHERE INVOICE.INV_NUMBER = LINE.INV_NUMBER GROUP BY CUS_CODE, LINE.INV_NUMBER) GROUP BY CUS_CODE; 36. Using the query results in Problem 35 as your basis, write a query to generate the total number of invoices, the invoice total for all of the invoices, the smallest invoice amount, the largest invoice amount, and the average of all of the invoices. (Hint: Check the figure output in Problem 35.) Your output must match Figure P7.36. FIGURE P7.36 Number of Invoices, Invoice Totals, Minimum, Maximum, and Average Sales SELECT Count([qryP7-34].[INV_NUMBER]) AS [Total Invoices], Sum([qryP7-34].[Invoice Total]) AS [Total Sales], Min([qryP7-34].[Invoice Total]) AS [Minimum Sale], Max([qryP7-34].[Invoice Total]) AS [Largest Sale], Avg([qryP7-34].[Invoice Total]) AS [Average Sale] FROM [qryP7-34];
  • 25. Another Random Scribd Document with Unrelated Content
  • 27. My Palace. built me a little palace, Somewhere in the ether land, Wherein my soul might revel And rest at my command. The spot, a royal summit, I let my will select, And Fancy came inspecting With Thought, the architect. We went down to the quarry For the foundation rock, And purchased hewn and polished Love’s marble corner block. For years we toiled together, And one day warm and sweet I woke and found my palace Before me and complete. It was a gorgeous building— The window lights of red Came from the sunset’s furnace, Or Northern light instead. Each peak, each tower and turret The sunlight’s love had won, And straight there came a voice From heaven and said “well done.” I planted a grove beyond it, And hedged up the terraced yard, And I dug a groove so a brooklet Could play on the level sward.
  • 28. I wanted a flower to cheer me, And off on a breezy slope I scattered the seed of roses And the purple heliotrope. I peopled the rooms with volumes Of men with talents rare, Who climbed upon Fame’s spire And waved their banners there. I purchased the costliest paintings, And swung them from the walls; And music, like harps of heaven, Resounded throughout the halls. I gave a royal banquet, The nuptial feast was spread, And then, when all was ready, There Love and I were wed. But when the guests departed, A rap came on the door, And a gaunt figure faced me I ne’er had seen before. “My name,” she said, “is Envy; I wish to stop with you; Your dwelling just completed, The inmates must be few.” Her breath, like fumes of sulphur, Into my face was blown, And like a demon’s curses Was her departing tone. The night came on, and fingers Tapped on the beveled glass, A face looked in the window With eyes that shone like brass;
  • 29. But Love beheld the visage, And o’er the window drew A shade that shut Suspicion Forever from my view. And then a pond’rous knocking Bombarded at the door, And like an earthquake’s tremor Upheaved the palace floor. I glanced into the key-hole, And, like the brand of Cain, I saw on Slander’s forehead A dark and bloody stain. I barred the palace entrance, And turning in the hall We faced another figure More dreadful than them all; He said: “My name is Ruin— Unbidden here I stand, To curse your happy homestead And desolate your land. “The lichen I have sprinkled Upon your crumbling tower, The ivy and the myrtle Shall choke each blooming flower.” And then he smote the castle, It trembled to its base, And fell? No, no—I shouted And laughed out in his face: “You can not wreck our palace, Love is the corner stone, And we are master workmen,” I said, in jocund tone.
  • 30. He seized his trailing garments, Departed with a groan, And love and I together Were once more left alone. Next day as they debated What course to next pursue, I heard a sweet voice calling— Love said the tone he knew. The step, low as a mother’s Upon the nursery floor, Was like advancing music That halted at our door. As when a fairy’s castle Yields to a magic key, Our door swung on the hinges The guest was—Sympathy. “Come in, our worthy sister,” I heard Love then repeat; “For happiness without you Could never be complete.” And while we sat together, Weaving our garland sweet, For many a bridal altar, For many a burial sheet, We heard another footstep; And, like an angel sent, There came and smiled upon us The face we loved—Content. The circle was completed— My palace stands sublime Still on that cloudland summit, And laughs at threats of Time.
  • 31. No curses thunder o’er us, No heavy rains can fall; For heaven’s open window Slants sunshine over all.
  • 33. Death of Summer. UMMER’S dying, close the shutters, Make the light subdued and sweet, The last accent that she utters I’ll record here at her feet. See, the pulses quiver faintly, But her heart, alas! ’tis still; See how pale she lies and saintly, Feel her hands, they’re white and chill. Close the eyes made sad from weeping, Smooth the tangles from her head, Leave her like an angel sleeping, Friends are here to view the dead. See, the rose a tear is dropping As she leans above her face, At the door the lily stopping, Finds her handkerchief of lace. There the two like sisters sorrow, As above the corse they bend, Planning for the sad to-morrow— For the burial of a friend. Then the daisy from the mountain, That in mourning shawl was dressed, Brought a snowdrow from the fountain, Lay it on the summer’s breast. To the pillow crept the lilacs, But the flowers at her throat Were the heliotrope and smilax— This was gained by casting vote—
  • 34. And the jasmine sought her fingers, While the fuschias kissed her hair; At her lip a violet lingers To deny them, who would dare? Then the autumn’s sunny treasure Came the sturdy golden rod, For the coffin took the measure, For the grave removed the sod. Long and mournful the procession That I watched across the hill, For to you I’ll make confession, Autumn doth my spirit kill. Drives me from the scene of sadness While on poison nature feeds; Decks her out in robes of gladness To conceal the heart that bleeds; At the summer’s grave there lingers None more sad to drop a tear Than the friend whose trembling fingers Write this in memoriam here.
  • 36. Spring and Summer. heard a footstep on the hill, The little brook began to trill, I looked—a sweet and childlike face, Reflected like a blooming vase, Was smiling from the water clear, With buttercups behind her ear. A flock of swallows hove in sight, On came the summer clad in white, With sunshine falling from her hair Upon her shoulders white and bare, And pressing through the tangled grass, A daisy rose to watch her pass.
  • 38. Under the Snow. HAT have you hidden down under the snow, So dear that you weep when the northern blasts blow? Why your face pressed to the cold window pane, Longing to mingle your tears with the rain— Is there something down under the snow? Is it only a blossom, a summer’s delight, That is freezing and dying this cold, bitter night? That is only a fancy, the floweret is warm, And the drift has enfolded it safe from the storm— Is there something yet under the snow? Something near to the heart down under the snow, That has robbed the wan cheek of its once carmine glow, That has stolen the beam of the eye—tears instead Bespeak how in anguish the sore heart hath bled For a little child under the snow. For a dear little prattler that littered the floor, And laughed as he tumbled your work o’er and o’er For a little gold head that made sunny the room, Now bright’ning the darkness and chill of the tomb, That is dreaming out under the snow. Only resting awhile in garments all white, Away from the blackness and sin of to-night; Away from the vice and the wrong of the street, Not heeding the song of the rain or the sleet, Still sleeping down under the snow. How many a mother her darling would lay
  • 39. In the last, narrow home—hide her treasure away— If only to know its soul was at rest With an innocent heart in an innocent breast, Far, far down under the snow!
  • 41. The Prettiest Girl in Town. AVE you e’er seen her, this beautiful girl With that classical head and complexion of pearl? So pale and enchanting that sometimes I deem Her a sweet revelation as when in a dream, Through wild variations of trouble and fear, You suddenly feel that an angel is near. Now guess, if you can, without half of that frown, For to me she’s the prettiest girl in the town. The poets all sing of these quaint Highland girls With enchanting dimples and loose tangled curls; Or they weave a love-tale from her budding lip’s glow While chasing the reindeer o’er mountains of snow; This is only the skill of a well tinctured pen, Dipped in Romance’s cup for the praises of men, Who value this maid in the coarse homespun gown Something less than the prettiest girl in the town. You must all have watched the calm light of her eyes, And ethereal figure with heavy drawn sighs; Pondered often in secret of some magic gift To win you this face—so like a snowdrift— I would whisper a secret: On Valentine’s day, With Cupid commune in a sly, cunning way, Else only in dreams she is thine; for a crown Could not purchase the prettiest girl in the town.
  • 44. I am Musing To-Night. am musing to-night in the fire-light’s glow, And watching the pictures that come and go; Like dissolving views on a magic screen Is the witchery of this changing scene; Though half I’m dreaming, though half awake, I fear to move lest the spell I break, Lest my fairy castles will break and fall, And down will tumble each beautiful wall. Thus still in a stupor I sit and gaze At the glowing embers and wanton blaze; I am smiling at Fancy; she tries in vain To lure me along with the mad’ning train That follow her footsteps—that to her cling, As flowers that garland the steps of spring; In moody silence I sit apart, Till memory conquers my sullen heart. Sweet Memory! sprite of my golden past! Your tinseled veil o’er me is cast; Subdued I yield like one enchained, And yet my freedom is only feigned; Back through the aisles of years that are gone, A willing captive you lead me on, Where I gleaned unbidden the joys of youth While the world was blossoming with love and truth. Before my heart could interpret a sigh, Or a tear-drop’s shadow creep into my eye, Ere I’d missed from the circle of friendship’s chain The link once lost that we ne’er regain,
  • 45. The future to me was a vast expanse, Its depth I could solve at a single glance, Knew not of the troubles that torture the soul Hidden away in its sober fold. Yet, to-night, as I dream in the gathering gloom, Only friends that are dear softly enter my room, Those who gladdened my life in its season of pain, Like a gleam of the sunshine along with the rain; These, these are the guests that encircle my hearth, Who come gliding like spirits back to the earth. What communion we hold only those ever know Who sit musing alone in the fire-light’s glow.
  • 47. A Curl. O-NIGHT, as I turned back the pages Of a book Time had fingered before, And whose leaves held the odor of ages, And the imprints of much usage wore, A little brown curl I discovered, That fell from the book to the floor. Had I sinned? Heaven grant me its pardon. Did a lover’s sad tear the page spot? Who pressed there that gem of the garden— The sweet flower, “forget-me-not?” It lay as if carved on a grave-stone, And all of its sweetness forgot. I held the curl up to the lamplight, And watching the gleam of its gold, There I heard with the rush of the midnight, A sad little story it told; But I promised the sacred old volume Its secret I would not unfold. But I would that the world knew its sorrow, The story I must not reveal; But go to your book case to-morrow. And each to your own heart appeal; And you’ll know why the tattered old volume The little curl tries to conceal.
  • 50. Somebody’s Face. TO M. A. B. HE blossoms are gone from the garden, But ’tis not of them I would speak; I want a sweet rose for my verses Like one that’s in somebody’s cheek. A red rose to kiss and to fondle, Whose leaves will not wither or die— To gladden each moment and banish The winter thoughts out of the sky. I want a low ripple of music To flow through these lines of my choice, Like a zephyr that moved through the summer, Now dwelling in somebody’s voice; A song that will be full of fragrance So sweet that its magic of words Will bring back the balm of the June time, Its memories glad, and the birds. The skies are so sunless and dreary, Unless I can find a deep blue To mix with the clouds of November They’ll still wear the dark, sober hue; But memory shows a bright heaven Reflected in somebody’s eye, And, thinking to-day of its beauty, The grey becomes blue in the sky. My dear little friend of the summer, Did you think in the meshes of song
  • 51. Welcome to our website – the perfect destination for book lovers and knowledge seekers. We believe that every book holds a new world, offering opportunities for learning, discovery, and personal growth. That’s why we are dedicated to bringing you a diverse collection of books, ranging from classic literature and specialized publications to self-development guides and children's books. More than just a book-buying platform, we strive to be a bridge connecting you with timeless cultural and intellectual values. With an elegant, user-friendly interface and a smart search system, you can quickly find the books that best suit your interests. Additionally, our special promotions and home delivery services help you save time and fully enjoy the joy of reading. Join us on a journey of knowledge exploration, passion nurturing, and personal growth every day! testbankfan.com