0% found this document useful (0 votes)
598 views10 pages

Lab Chapter # 8

This document provides the instructions and questions for a lab assignment on SQL queries. It asks students to: 1) Perform 10 SQL queries on tables in the JustLee database, listing specific fields from orders, customers, books, and authors based on filtering criteria like dates, categories, and names. 2) Write additional queries to find book titles and categories matching two patterns, books in specific categories published by certain publishers and priced over $45, and books generating a profit of over $10 ordered by highest profit. 3) Document the SQL statements used to find the data requested for future reference. The assignment tests students' ability to write various types of SQL queries to extract and filter information from multiple database

Uploaded by

Kovid Behl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
598 views10 pages

Lab Chapter # 8

This document provides the instructions and questions for a lab assignment on SQL queries. It asks students to: 1) Perform 10 SQL queries on tables in the JustLee database, listing specific fields from orders, customers, books, and authors based on filtering criteria like dates, categories, and names. 2) Write additional queries to find book titles and categories matching two patterns, books in specific categories published by certain publishers and priced over $45, and books generating a profit of over $10 ordered by highest profit. 3) Document the SQL statements used to find the data requested for future reference. The assignment tests students' ability to write various types of SQL queries to extract and filter information from multiple database

Uploaded by

Kovid Behl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Lab Chapter # 8

Total Marks: 10

Student Name : KOVID BEHL_________________ Student Id #: N01579154_________

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';

SELECT order#, orderdate


FROM orders
WHERE orderdate <= '01-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';

c) another operator not used in a or b.


SELECT title, category
FROM books
WHERE category IN ('CHILDREN', 'COOKING')
9. Use a search pattern to find any book title with “A” for the second letter and “N”
for the fourth letter. List each book’s ISBN and title. Sort the list by title in
descending order.
SELECT isbn, title
FROM books
WHERE title LIKE '_A_N%'
ORDER BY title DESC;

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';

c) a search pattern operation.


SELECT title, pubdate
FROM Books
WHERE category = 'COMPUTER' AND pubdate LIKE '%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;

2. A customer service representative is trying to identify all books in the Computer or


Family Life category and published by Publisher 1 or Publisher 3. However, the
results shouldn’t include any book selling for less than $45.00. For each request,
create a document showing the SQL statement and the query results.
SELECT isbn, title, category, pubid, retail
FROM books
WHERE (category = 'COMPUTER' OR category = 'FAMILY')
AND pubid IN ('1','3')
AND retail >= 45;

You might also like