SQL Practice Problems
SQL Practice Problems
For the following exercises the collection name is: PREMIERE (see ERD on Page 5)
Selecting Attributes and Sorting
1.
2. We can reduce our shipping costs by sorting by Zip_Code. Produce a listing that
does this and also shows the customer's name and address.
3. Produce a list showing Part_Number, Part_Description, On_Hand, and Price sorted
by Warehouse and Class. In this case Warehouse is the majour sort key and Class
is the minor sort key.
Selecting Rows
4. List all the attributes in ORDERLINE (might be called ORDER_PART) selecting
only rows where the Number_Ordered is greater than or equal to 2.
5. List all customers Last_Name and First_Name Whose Credit_Limit is less than or
equal to $1000.
6. List all customers Last_Name and First_Name Whose Credit_Limit is greater than
or equal to $1000 and whose Zip_Code is 49219.
7. Using the PART table, select rows that have a Part_Number that begins with B
=================================================
Answers
Practice Exercises SQL (1)
For the following exercises the collection name is: PREMIERE
Selecting Attributes and Sorting
1.
Selecting Rows
4. List all the attributes in ORDERLINE (might be called ORDER_PART) selecting
only rows where the Number_Ordered is greater than or equal to 2.
SELECT *
FROM PREMIERE.ORDERLINE
WHERE Number_Ordered >= 2
5. List all customers Last_Name and First_Name Whose Credit_Limit is less than or
equal to $1000.
SELECT *
FROM PREMIERE.PART
WHERE SUBSTR(Part_Number , 1, 1) = B
Note: the substring function uses Part_Number starting at position 1 for a
length of 1. Thats how we can isolate the first character of Part_Number.
Joins
8. Using 2 tables, list the Part_Number, Part_Description, Number_Ordered and
Quoted_Price.