Database Exercises
Chapter
1
2
3
4
5
6
7
8
9
10
11
12

Sally’s Pet Store
- List the female cats that are registered.
- List the customers who live in Vermont (VT).
- Which dogs have a list price greater than $270?
- Which dogs cost less than $100 or were registered and cost more than $250?
- List the customers who purchased something in January.
- List the suppliers who delivered cats in March.
- List the birds with gold in their color.
- Which employees sold items or animals between June 15 and June 30? (List each employee only once.)
- Which animals were born no more than 30 days after they were ordered?
- What is the most expensive (SalePrice) cat ever sold?
- Which dog was sold at the greatest discount (ListPrice-SalePrice)?
- What is the highest-value merchandise order (total of quantity*cost) ever placed?
- What is the most number of animals ever sold at one time (on the same sale)?
- List the number of sales that took place each month. Hint: You need to find the function that returns the month number of the SaleDate.
- What are the total values of sales of merchandise items by category?
- Which employee sold the most merchandise by value in June?
- Which supplier has received the most money (Cost) for cats?
- Which category of animal provides the highest average profit percentage (using SalePrice and Cost)?
- Who is the best customer measured by total value of merchandise purchases for the first half of the year?
- On average, which supplier is slowest to ship merchandise?
- What is the oldest cat on the day it was sold?
- Compare the average sale price of registered dogs to unregistered dogs?
- Has the company sold more female or male black cats?
- What is the most expensive merchandise item sold (SalePrice)?
- Which merchandise item was sold at the greatest percentage discount from list price?
Rolling Thunder Bicycles

Write the SQL statements that will answer questions 26 through 50 based on the tables in the Rolling Thunder database.
- List the pries of race bikes smaller than 53 cm shipped to Florida (FL) in 2004.
- Who bought road bikes in Massachusetts (MA) with a frame size greater than 58 cm in 2005?
- Who bought full suspension mountain bikes in Colorado (CO) in 2006 or bought mountain bikes in Texas (TX) that had red in the color in 2006?
- List employees who sold red road bikes to New York (NY) in the first quarter of 2005.
- What is the most expensive race bike sold in 2006?
- Who bought the least expensive mountain (or full suspension) bike in Idaho (ID) in 2005?
- List the components installed on bike serial number 32151, in descending order of price.
- What is the most expensive (ListPrice) component (not a frame) held in inventory and how many units are on hand?
- List the employees who painted road bicycles started in February 2006. Hint: You will have to change the join columns.
- List the manufacturers who sold us more than $100,000 (list price) on a single order in 2005.
- How many components were installed by Tudjman on March 17, 2006?
- Which customer received the greatest percentage discount off list price for a bicycle order in 2005?
- Compare the average sale price of race bikes in 2006 based on the type of down tube (e.g., Carbon, Aluminum, Titanium, or Cro-moly).
- How does the total weight of the Campy Record 2004 groupo compare to that of the Shimano Dura Ace 2003 groupo? Hint: You cannot use the Weight column in the Groupo table. Bonus point: what is the weight in pounds?
- What was the most popular model type (by count) sold in January 2006?
- In which state did the company sell the most race bikes with a frame size larger than 58 cm in 2005?
- Which employee had the most sales by value in March 2006?
- On average, from which manufacturer did it take the longest time to receive an order in 2005?
- Ignoring discounts and labor costs, what is the estimated profit made on components installed in May 2005?
- What was the most popular paint style for mountain (or full suspension) bikes ordered in August 2006?
- Which customer(s) purchased the most number of bicycles in a single month? Hint: Use a function that returns the month and year from a date.
- Which manufacturer provided the highest average percent discount on orders placed in 2005?
- On average, which type of component weighs the most for road bikes versus mountain bikes?
- In 2006, what was the average price of bikes sold with the help of retail stores compared to those sold direct (StoreID of 1 or 2)? Hint: Use two separate queries.
- In 2005, which employee gave the highest total value of discounts on bicycle sales?
Corner Med

- List the physicians and their emergency phone numbers sorted by name.
- List the patients and their phone numbers who visited the clinic between July 1, 2007 and July 7, 2007.
- List the male patients under 30 years old who were treated by Nurse Cameron in June 2007. Hint: Use a function to subtract dates by years.
- List all of the patients who were diagnosed with a “dog bite” in 2007.
- List all of the procedure codes that refer to the uvula.
- List all of the potential diagnoses involving swimming.
- List the patients who did not have insurance coverage for a visit in May 2007.
- List all of the employees and procedures they performed for Debra Santini in 2007.
- List all of the employees who have performed a procedure in the 51xx category (any procedure beginning with 51) in the second half of 2007.
- List the patients who had Medicare coverage for at least one visit in 2007. List each person only once if there were multiple visits.
- How many patient visits occurred in May 2007?
- Which patient had the most visits in 2007?
- What is the total amount of revenue generated (not necessarily paid) in June 2007?
- How much money was received from each insurance company in the first quarter of 2007?
- Diagnostic codes are grouped by the initial letters or numbers of the code. The top-level group is the first character of the code. Count the number of patients diagnosed with each of the top-level codes. Hint: Use a function to return just the first character of the code.
- On average, how many days did it take to receive money from each insurance company in 2007?
- Which employee billed the most revenue charges for 2007?
- What is the most number of days it took our company to submit a bill to an insurance company in 2007?
- What is the most number of employees who treated a patient in one visit in 2007?
- What is the most number of patients seen in one day in August 2007?