Sei sulla pagina 1di 4

SQL Simple Queries

Use the following database schema to express the following queries in SQL. The tables
containing sample data are attached.
CUSTOMER (CUSTID, CUSTNAME, ANNUALREVENUE, CUSTTYPE)
SHIPMENT (SHIPMENT#, CUSTID, WEIGHT, TRUCK#, CITYNAME, SHIPDATE)
TRUCK (TRUCK#, DRIVERNAME)
CITY (CITYNAME, POPULATION)

1. Give IDs for customers who have sent shipments to Tucson or Baltimore (be sure to list each
customer only once).

2. Give names and annual revenue of customers that are not retailers.

3. How much did our heaviest shipment weigh?

4. Which shipments weighed more than 50 pounds and went to Baltimore?

5. Create a list of retail customers who have at least $20 million in annual revenue. The list
should be presented in order of annual revenue from highest to lowest.

---SEE NEXT PAGE---

6. How many different customers have sent shipments to cities with names starting with B?

7. Give the shipment number, truck number, and weight of all shipments for the past 90 days.

8. Give names and monthly revenue of customers having annual revenue exceeding $10 million
but less than $15 million.

SQL Join Queries


Use the following database schema to express the following queries in SQL. The tables
containing sample data are attached.
CUSTOMER (CUSTID, CUSTNAME, ANNUALREVENUE, CUSTTYPE)
SHIPMENT (SHIPMENT#, CUSTID, WEIGHT, TRUCK#, CITYNAME, SHIPDATE)
TRUCK (TRUCK#, DRIVERNAME)
CITY (CITYNAME, POPULATION)

1. What are the names of customers who have sent shipments to Baltimore?

2. To what destinations have customers with revenue less than $30 million sent packages?

3. What are the names and populations of cities that have received shipments weighing over
100 pounds?

4. Who are the customers (names) having over $20 million in annual revenue who have sent
shipments weighing less than 100 pounds?

5. Who are the retail customers (names) who have sent shipments weighing less than 100
pounds or have sent a shipment to Tucson?

6. Who are the drivers who have delivered shipments for customers with annual revenue over
$20 million to cities with populations over 1 million?

---SEE NEXT PAGE---

SQL Subqueries
Use the database schema above to express the following queries in SQL. The tables containing
sample data are included in file SQLData.pdf.
1. List the cities that have received shipments from customers having less than $15 million in
annual revenue.

2. List the names of drivers who have delivered shipments weighing over 100 pounds.

3. List the name and annual revenue of customers who have sent shipments weighing under 100
pounds.

4. List the name and annual revenue of customers whose shipments have been delivered by Sue
Brown.

5. Provide details for the shipment(s) that weigh the most.

6. In terms of annual revenue, list the name of our smallest customer(s)?

7. Which customers (provide names) have not yet shipped anything?

Potrebbero piacerti anche