You are on page 1of 1

SQL Practice 2

Chapters 7 and 8 in the Coronel/Rob textbook use the database for a hardware store called SaleCo. Please review the
following SaleCo diagram –you’ll need to refer to it when writing SQL queries.

NOTES: (1) The LINE table stores data about details of each transaction. Suppose an invoice is for three different
products that the customer purchased, the LINE table associated with that invoice will contain three lines with each line
number listing invoice number, line number, product code, quantity of the product purchased (under LINE_UNITS
column), and price of the product (under LINE_PRICE column).
(2) In the PRORDUCT table, the P_QOH column indicates quantity on hand (quantity in stock) for each product; P_MIN
column lists the minimum quantity, i.e., when quantity on hand gets down to this level, the product needs to be re-ordered;
the P_DISCOUNT column lists price discount for the product - for example .07 would indicate a 7% discount.
Log into your Oracle database account, open and run the Saleco.sql script (this script is available in Canvas) to create
tables for the Chapters 7 and 8 examples database called Saleco. Then practice writing and running SQL queries for the
following problems.

QUERY #1: Show all of the data from the Product table. Sort the output by price from the highest to the lowest
price.

SELECT * FROM product


ORDER BY p_price DESC;

QUERY #2: Show product code, description, and price for those products whose price is less than $50.

SELECT p_code, p_descript, p_price FROM product


WHERE p_price < 50;

QUERY #3: Show first name, last name, and phone numbers of customers whose last name is Smith.

SELECT cus_fname, cus_lname, cus_phone FROM customer


WHERE cus_lname = ’Smith’;

QUERY #4: Show vendor names and vendor state for all vendors from Florida (FL).

SELECT v_name, v_state FROM vendor


WHERE v_state = ‘FL’;

QUERY #5: Show vendor names and vendor state only for those vendors who are from Florida (FL) and whose name begins
with the letter B.

SELECT v_name, v_state FROM vendor


WHERE v_state = ‘FL’ AND v_name LIKE ‘B%’

You might also like