Database Lab 3
September 20, 2013
To become experienced with SQL Query language
Make your own copy of the Henry Books database.
Create and test queries for the following. Use phpmyadmin to enter and test the queries. Turn in the queries, and the output.
1. List the name of each publisher that’s not located in New York.
2. List the title of each book published by Penguin USA.
3. List the title of each book that has the type MYS.
4. List the title of each book that has the type SFI and that is in paperback.
5. List the title of each book that has the type PSY or whose publisher code is JP.
6. List the title of each book that has the type CMP, HIS, or SCI.
7. How many books have a publisher code of ST or VB?
8. List the title of each book written by Dick Francis.
9. List the title of each book that has the type FIC and that was written by John Steinbeck.
10. For each book with coauthors, list the title, publisher code, type, and author names (in the order listed on the cover).
11. How many book copies have a price that is greater than $20 but less than $25?
12. List the branch number, copy number, quality, and price for each copy of The Stranger.
13. List the branch name, copy number, quality, and price for each copy of Electric Light.
14. For each book copy with a price greater than $25, list the book’s title, quality, and price.
15. For each book copy available at the Henry on the Hill branch whose quality is excellent, list the book’s title and author names (in the order listed on the cover).
16. Create a new table named
FictionCopies using the data in the
Price columns for those books that have the type FIC.
17. Ray Henry is considering increasing the price of all copies of fiction books whose quality is excellent by 10%. To determine the new prices, list the book code, title, and increased price of every book in the
FictionCopies table. (Your computed column should determine 110% of the current price, which is 100% plus a 10% increase.)
18. Use an update query to change the price of each book in the
FictionCopies table with a current price of $14.00 to $14.50.
19. Use a delete query to delete all books in the
FictionCopies table whose quality is poor.
SQL Aggregate Functions
SQL aggregate functions return a single value, calculated from values in a column.
Useful aggregate functions:
- AVG() - Returns the average value
- COUNT() - Returns the number of rows
- FIRST() - Returns the first value
- LAST() - Returns the last value
- MAX() - Returns the largest value
- MIN() - Returns the smallest value
- SUM() - Returns the sum