Practice Questions DB
Practice Questions DB
Practice Questions DB
1. List the customer number, name (first and last), and balance of customers.
2. List the customer number, name (first and last), and balance of customers who reside in Colorado
(CustState is 'CO').
3. List all columns of the Product table for products costing more than $50. Order the result by product
manufacturer (ProdMfg) and product name.
select *
from product
where prodprice > 50
order by prodmfg, prodname
4. List the order number, order date, and shipping name (OrdName) of orders sent to addresses in Denver or
Englewood.
5. List the customer number, name (first and last), city, and balance of customers who reside in Denver with
a balance greater than $150 or who reside in Seattle with a balance greater than $300.
6. List the cities and states where orders have been placed. Remove duplicates from the result.
7. List all columns of the OrderTbl table for Internet orders placed in January 2004. An Internet order does
not have an associated employee.
select *
from ordertbl
where orddate between '01-Jan-04' and '31-Jan-04'
and empno is null
8. List all columns of the OrderTbl table for phone orders placed in February 2004. A phone order has an
associated employee.
select *
from ordertbl
where orddate between '01-Feb-04' and '28-Feb-04'
and empno is not null
9. List all columns of the Product table that contain the words 'Ink Jet' in the product name.
select *
from product
where prodname like '%Ink Jet%'
10. List the order number, order date, and customer number of orders placed after January 23, 2004, that are
shipped to Washington recipients.
11. List the average balance of customers by city. Only include customers residing in Washington state ('WA').
12. List the average balance of customers by city and short zip code (the first five digits of the zip code). Only
include customers residing in Washington state ('WA'). In PostgreSQL and Oracle, the expression substr
(CustZip, 1, 5) returns the first five digits.
13. List the average balance and number of customers by city. Only include customers residing in Washington
state ('WA'). Eliminate cities in the result with less than two customers.
14. List the number of unique short zip codes and average customer balance by city. Only include customers
residing in Washington state ('WA'). Eliminate cities in the result in which the average balance is less than
$100. In PostfeqSQL and Oracle, the expression substr (CustZip, 1, 5) returns the first five digits.
16. List the order number, order date, customer number, and customer name (first and last) of orders placed
in January 2004 sent to Colorado recipients.
17. List the order number, order date, customer number, and customer name (first and last) of orders placed
in January 2004 placed by Colorado customers (CustState) but sent to Washington recipients (OrdState).
18. List the customer number, name (first and last), and balance of Washington customers who have placed
one or more orders in February 2004. Remove duplicate rows from the result.
19. List the order number, order date, customer number, customer name (first and last), employee number,
and employee name (first and last) of January 2004 orders placed by Colorado customers.
21. List the product number, name, and price of products ordered by customer number C0954327 in January
2004. Remove duplicate products in the result. (????)
22. List the customer number, name (first and last), order number, order date, employee number, employee
name (first and last), product number, product name, and order cost (OrdLine.Qty * ProdPrice) for
products ordered on January 23, 2004, in which the order cost exceeds $150.
23. List the order number and the total amount of the order for orders on January 23, 2004. The total amount
of an order is the sum of the quantity times the product price for each product on the order.
24. List the order number, order date, customer name (first and last), and total amount of the order for
orders on January 23, 2004. The total amount of an order is the sum of the quantity times the product
price for each product on the order.
27. List the employee number, employee name (first and last), and total amount of commissions on orders
taken in January 2004. The amount of a commission is the sum of the dollar amount of products ordered
times the commission rate of the employee.
28. Using the join operator style, list the product name and the price of all products ordered by Beth Taylor in
January 2004. Remove duplicate rows from the result.
29. For Colorado customers, compute the number of orders placed in January 2004. The result should include
the customer number, the last name, and the number of orders placed in January 2004.
30. For Colorado customers, compute the number of orders placed in January 2004 in which the orders
contain products made by 'Connex'.
31. For each employee with a commission rate of less than 0.04, compute the number of orders taken in
January 2004. The result should include the employee number, the employee last name, and the number
of orders taken.
32. For each employee with a commission rate of greater than 0.03, compute the total commission earned
from orders taken in January 2004. The total commission earned is the total order amount times the
commission rate. The result should include the employee number, the employee last name, and the total
commission earned.
33. List the order number, the order date, the customer address and the shipping address of orders in which
any part of the shipping address (street, city, state, and zip) differs from the customers address.
select ordno, orddate, custstreet, custcity, custstate, custzip, ordstreet, ordcity, ordstate, ordzip
from ordertbl natural join customer
where ordstreet <> custstreet or ordcity <> custcity or custstate <> ordstate or ordzip <> custzip
34. For Colorado customers, compute the number of unique products ordered. If a product is purchased on
multiple orders, it should be counted only one time. The result should include the customer number, the
customer last name, and the number of unique products ordered.
35. For each 'Connex' product, compute the number of unique customers who ordered the product in January
2004. The result should include the product number, the product name, and the number of unique
customers.
37. Using two Type I nested queries, list the product number, the name, and the price of products with a price
greater than $150 that were ordered on January 23, 2004.
38. Using two Type I nested queries and another join style, list the product number, the name, and the price
of products with a price greater than $150 that were ordered in January 2004 by customers with balances
greater than $400.
39. Using a Type I nested query, list the customer number and the customer name of Colorado customers
who have not placed orders in February 2004.
40. List the product number and the name of products contained on every order placed on January 7, 2004,
through January 9, 2004.
42. List the employee number and the employee name (first and last) of employees who have taken orders in
January 2004 from every Denver customer.
43. For Colorado customers, compute the average amount of their orders.
44. For Colorado customers, compute the average amount of their orders and the number of orders placed.
The result should include the customer number, the customer last name, the average order amount, and
the number of orders placed.
45. List the employee number, employee name (first and last), commission rate, supervising employee name
(first and last), and commission rate of the supervisor.
47. Using a Type II nested query, list the customer number, the name (first and last), and the city of each
customer who has a balance greater than $150 and placed an order in February 2004.
48. Using a Type II nested query, list the customer number and the customer name of Colorado customers
who have not placed orders in February 2004.
49. List the order number and the order date of orders containing only one 'Ink Jet' product. An ink jet
product contains the words 'Ink Jet' in the product description.
50. List the order number and the order date of orders containing every 'Ink Jet' product.