Lab Chapter # 8
Lab Chapter # 8
Total Marks: 10
Lab exercises You need to be present in the class for your lab to be graded and are to
be submitted within 3 Hours after the class, failing to do the will result in ZERO grade.
Hands-On Assignments
To perform the following assignments, refer to the tables created in the JLDB_Build_8.sql
script attached with this assignment. Open the file and copy all the contents and paste in SQL
Developer. Select the commands and RUN to execute the SQL commands.
Give the SQL statements and output for the following data requests:
1. Which customers live in New Jersey? List each customer’s last name, first name,
and state.
SELECT lastname, firstname, state
FROM customers
WHERE state= 'NJ';
2. Which orders shipped after April 1, 2009? List each order number and the date it
shipped.
SELECT order#, shipdate
FROM orders
WHERE shipdate > '01-APR-09';
3. Which books aren’t in the Fitness category? List each book title and category.
SELECT title, category
FROM books
WHERE category != 'FITNESS';
4. Which customers live in Georgia or New Jersey? Put the results in ascending order
by last name. List each customer’s customer number, last name, and state. Write
this query in two different ways.
SELECT customer#, lastname, state
FROM customers
WHERE state='GA' OR state='NJ'
ORDER BY lastname
5. Which orders were placed on or before April 1, 2009? List each order number and
order date. Write this query in two different ways.
SELECT order#, orderdate
FROM orders
WHERE orderdate < '02-APR-09';
6. List all authors whose last name contains the letter pattern “IN.” Put the results in
order of last name, then first name. List each author’s last name and first name.
SELECT fname, lname
FROM author
WHERE lname LIKE '%IN%'
ORDER BY lname, fname;
7. List all customers who were referred to the bookstore by another customer. List
each customer’s last name and the number of the customer who made the referral.
SELECT lastname, referred
FROM customers
WHERE referred IS NOT NULL;
8. Display the book title and category for all books in the Children or Cooking
categories. Create three different queries to accomplish this task:
a) a search pattern operation,
SELECT title, category
FROM books
WHERE category LIKE '%C%N%';
b) logical operator, and
SELECT title, category
FROM books
WHERE category = 'CHILDREN' OR category = 'COOKING';
10. List the title and publish date of any computer book published in 2005. Perform the
task of searching for the publish date by using three different methods:
a) a range operator
SELECT title, pubdate
FROM books
WHERE category = 'COMPUTER'
AND pubdate BETWEEN '01-JAN-05' AND '31-DEC-05';
b) a logical operator
SELECT title, pubdate
FROM books
WHERE category = 'COMPUTER'
AND pubdate >= '01-JAN-05' AND pubdate <= '31-DEC-05';
Advanced Challenge
To perform these activities, refer to the JustLee database tables. During an afternoon at work,
you receive various requests for data stored in the database. As you fulfill each request, you
decide to document the SQL statements you used to find the data to assist with future requests.
The following are two of the requests that were
made:
1. A manager at JustLee Books requests a list of the titles of all books generating a
profit of at least $10.00. The manager wants the results listed in descending order,
based on each book’s profit.
SELECT title, (retail - cost) AS "Profit"
FROM books
WHERE (retail - cost) >= 10
ORDER BY (retail - cost) DESC;