Академический Документы
Профессиональный Документы
Культура Документы
List the customer number, the name (first and last), and the balance of customers who
reside in Colorado (Cust-State is CO).
Ans:
Select custno,custfirstname,custlastname,custbal
from Customer
where CustState='CO'
5. List the customer number, the name (first and last), the city, and the balance of
customers who reside in Denver
with a balance greater than $150 or who reside in Seattle with a balance greater than $300.
Ans:
select custno,CustFirstName,CustLastName,CustCity,CustBal
from Customer
where (CustCity='Denver' and CustBal>150) or( CustCity='Seattle' and
CustBal>300)
7. List all columns of the OrderTbl table for Internet orders placed in January 2013. An
Internet order does not have
an associated employee.
Ans:
select * from OrderTbl
where OrdDate between '01-Jan-2013' and '21-Dec-2013'
and EmpNo is null
9. List all columns of the Product table that contain the words Ink Jet in the product name.
Ans:
select * from Product
where ProdName like '%Ink Jet%'
12.List the order number, order date, customer number, and customer name (first and last)
of orders placed in January
2013 placed by Colorado customers (CustState) but sent to Washington recipients
(OrdState).
Ans:
select O.ordno,O.OrdDate,C.CustNo,C.CustFirstName,C.CustLastName
from OrderTbl O,Customer C
WHERE O.CustNo=C.CustNo and O.OrdDate between '01-Jan-2013' and '31-Jan-2013'
and C.CustState='CO' and O.OrdState='WA'
15. List the employee number, name (first and last), and phone of employees who have
taken orders in January 2013
from customers with balances greater than $300. Remove duplicate rows in the result.
Ans:
select distinct E.EmpNo,E.EmpFirstName,E.EmpLastName,E.EmpPhone
from Employee E,OrderTbl O,Customer C
where O.OrdDate between '1-Jan-2013' and '31-Jan-2013'
and C.CustBal>300
and O.EmpNo=E.EmpNo
and O.CustNo=C.CustNo
18. List the average balance of customers by city. Include only customers residing in
Washington state (WA).
24. List the customer number, customer name (first and last), the sum of the quantity of
products ordered, and the
total order amount (sum of the product price times the quantity) for orders placed in January
2008. Only include
products in which the product name contains the string Ink Jet or Laser. Only include
customers who have ordered
more than two Ink Jet or Laser products in January 2013.
Ans:
select C.CustNo,C.CustFirstName,C.CustLastName,SUM(OL.Qty) As ProdQty,
SUM(OL.Qty*p.ProdPrice) as TotalOrderAmt
from Customer C Join OrderTbl O on C.CustNo=O.CustNo
Join OrdLine OL on OL.OrdNo=O.OrdNo join Product P on P.ProdNo=OL.ProdNo
where O.OrdDate between '1-Jan-2013' and '31-Jan-2013'
and P.ProdName like '%Ink Jet%' or P.ProdName like '%Laser%'
group by c.CustNo,C.CustFirstName,C.CustLastName
having COUNT(OL.Qty ) >2