Lab9 Adv SQL
Lab9 Adv SQL
Lab 09
Objectives:
The purpose of this lab is to familiarize you with tables and advanced query operations.
LAB 09 – SUBMISSION
You will be submitting a Word document with the questions listed followed by the answers with the
SQL queries and screenshots of the results. Use () brackets for subqueries and try to run the
subquery first if it executes fine without any errors.
In the Word document header, you should have your Name, Student ID number, section. Each
question should have SQL Query followed by screenshots of the result of SQL queries
QUESTION 1
Write a SQL statement using multi-row functions to display the total number of customers and total credit
limit given to all RETAILCUSTOMERS.
QUESTION 2
Write a SQL statement using multi-row functions to display the minimum credit limit, maximum credit limit
and average credit limit for all RETAILCUSTOMERS.
QUESTION 3
Write a SQL statements using multi-row functions to display the total distinct order dates and total distinct
status in RETAILORDERS table.
QUESTION 4
Write a SQL statement using multi-row functions to display the customer number and customer name who
recently ordered from RETAILORDERS table.
QUESTION 5
Write a SQL statement using multi-row functions to display RETAILEMPLOYEES who go first in line by first
name and last in line by first name
QUESTION 6
Write a SQL statement using multi-row functions to display the distinct last names in RETAILEMPLOYEES
that end with letter ‘G’ and also display the count of distinct last names that end with letter ‘G’ in the same
query using “Over () function”
QUESTION 7
Write a SQL statement using group functions to display the sales rep id and the count of sales repid in
RETAILCUSTOMERS table.
QUESTION 8
Lab-09-Name-Studentid
Write a SQL statement using group functions to display the sum and average of the price of each item in
ORDERDETAILS when they are grouped by order number.
QUESTION 9
Write a SQL statement to display the office code and the number of RETAILEMPLOYEES’s in each office.
QUESTION 10
Write a SQL statement using group functions to display customer name and customer number who have
same credit limit and limit the display by showing RETAILCUSTOMERS who have credit limit above 4000.
Display the above query sorted by customer name in ascending order.
QUESTION 11
Write a SQL query using subqueries to display payment date in the format “DD-MON-YYYY’ along with
customer number of those customer number which is below the customer number of retail customer name
‘Lisboa Souvenirs’, Inc’ and the payment date are above the order date of retail order number 10361.
QUESTION 12
Write a SQL query using subqueries, single row functions to display the retail product’s product name and
quantity in stock where the product names contain the first character of retail employee’s first name of
employee number 1286 and the quantity in stock is above the minimum payment amount of customer
number 398.
QUESTION 13
Write a SQL query using subqueries to display the retail payment’s customer number along with their
minimum payment amount grouped by their customer number which are above the minimum payment
amount of customer number 462.
QUESTION 14
Write a SQL query using subqueries to display the order details’ order number, and their average price each
of those below the average price each of order number 10129 and those product code that are in the product
code list of retail products’ product line ‘Vintage Cars’
QUESTION 15
Write a SQL query using subqueries to find all retail customers that have customer number
greater than 'Mini Wheels Co.' and whose credit limit are greater than customer number 121 (Hint
2 subqueries are needed and display customer number, credit limit, customer name in the main
query)
QUESTION 16
Write a SQL query using subqueries to find all retail employees that have employee number greater than
'Andy Fixter' and whose office code are less than “Barry Jones” (Hint 2 subqueries are needed and display
employee number, employee name, office code in the main query)
Lab-09-Name-Studentid
QUESTION 17
Write a SQL query using subqueries to find all retail customers who have the same credit limit as the
maximum credit limit of all retail customers (Hint 1 subquery and group function are needed and display
contact full name, customer number and credit limit in the main query)
QUESTION 18
Write a SQL query using subqueries to find all retail orders who have the order date above the minimum
order date and who have ordered before order number 10107(Hint 2 subquery and group function are
needed and display order number, customer number and order date in the main query)
QUESTION 19
Write a SQL query using subqueries to display all orders with minimum order date grouped by the customer
number and less than customer number 458’s order date (Hint you will have group by
clause, group function and 1 subquery to display the customer number and the minimum of order date in
retail orders table)
QUESTION 20
Write a SQL query using subqueries to find the order details whose price of each item are above the average
of the lowest price item (Hint use over () function in main query, you will have to group by clause, group
function in 1 subquery to display the quantity, price, item count of the order number in orders details table)