SQL Assignment
SQL Assignment
Customer Table
SQL
);
Department Table
SQL :
Orderline Table
);
Orders Table
);
Products Table
SQL
);
Salesrep
SQL
);
Answers
1.
3.
SELECT F_Name,LastName FROM customer where custNo in(select DISTINCT(custno) from orde
rs);
5.
SELECT ProductNo FROM Product WHERE ProductNo not IN(select DISTINCT(ProductNo) from o
rderline);
7.
8.
SELECT CustNo FROM customer WHERE CustNo not in (SELECT DISTINCT(CustNo) from orders)
10.
12.
SELECT f_name,LastName FROM customer WHERE Balance = (SELECT max(Balance) from custome
r);
14. SELECT count(*)as ord_qty, CustNo FROM orders GROUP by CustNo having count(*)>3;
15. SELECT count(*),OrdStatus FROM orders GROUP by ordstatus order by OrdStatus;
16.
SELECT count(*) as total_count, salesrep.SalesRepFName,salesrep.SalesRepLastName FROM
orders,salesrep where salesrep.SalesRepNo = orders.SalesRepNo group by orders.salesrep
no having count(*)>=3;
17.
18.
SELECT max(unitprice) from product where unitprice not in (SELECT max(unitprice) from
product);
19.
21.
SELECT * FROM `product` WHERE ProductNo not in (SELECT DISTINCT(ProductNo) from orderl
ine);
24.
SELECT salesrep.salesreplastname , salesrep.SalesRepFName FROM orders, salesre
p where OrderNo = 12800 and orders.SalesRepNo = salesrep.SalesRepNo;
25.
SELECT COUNT(*) as qty FROM orders WHERE SalesRepNo='s5' AND OrdDate>='2002-01-01' and
OrdDate <='2002-12-31';