This action might not be possible to undo. Are you sure you want to continue?
SNAME Peel Serres Motika Rafkin Axelrod
CITY London San Jose London Barcelona New york
COMM .12 .13 .11 .15 .1
TABLE CUST CNUM 2001 2002 2003 2004 2006 2007 CNAME Hoffman Giovanne Liu Grass Clemens Pereira CITY London Rome San Jose Brelin London Rome RATING 100 200 300 100 300 100 SNUM 1001 1003 1002 1002 1007 1004
ORDERS ONUM 3001 3003 3002 3005 3006 3009 3007 3008 3010 3011 AMT 18.69 767.19 1900.10 5160.45 1098.16 1713.23 75.75 4723.00 1309.95 9891.88 ODATE 03-OCT-94 03-OCT-94 03-OCT-94 03-OCT-94 04-OCT-94 04-OCT-94 05-OCT-94 05-OCT-94 06-OCT-94 06-OCT-94 CNUM 2008 2001 2007 2003 2008 2002 2004 2006 2004 2006 SNUM 1007 1001 1004 1002 1007 1003 1002 1001 1002 1001
Excercises 1. Display snum,sname,city and comm of all salespeople.
Select snum, sname, city, comm from salespeople; 2. Display all snum without duplicates from all orders. Select distinct snum from orders; 3. Display names and commissions of all salespeople in london. Select sname,comm from salespeople where city = London ; 4. All customers with rating of 100.
All orders taken on Oct 3Rd and Oct 4th 1994. Select sname.10 and comm < 0. odate from orders. All salespeople either in Barcelona or in london. All orders for more than $1000. (Boundary values should be excluded) Select sname. All salespeople with commission between 0. 8.10. 11. . amt. Select cname from cust where city = San Jose or rating > 200. amount and date form all rows in the order table.10 and 0. Select * from orders where amt > 1000. 12. city from salespeople where city in ( Barcelona . London ). All customers in San Jose. All customers with NULL values in city column. All customers excluding those with rating <= 100 unless they are located in Rome.12. 10.10 and city = London . Select ordno. Produce orderno. comm from salespeople where comm > 0. Select cname from cust where rating > 200. Select sname. 7. All customers who were either located in San Jose or had a rating above 200. who have rating more than 200.12. 5. 6. 9. 04-OCT-94 ). Select cname from cust where city is null. Select * from orders where odate in ( 03-OCT-94 . 14. 13.Select cname from cust where rating = 100. Select cname from cust where rating <= 100 or city = Rome . Names and citires of all salespeople in london with commission above 0. city from salepeople where comm > 0.
Select count(distinct snum) from orders.snum.snum. 24. 20.cnum and orders. snum order by odate. Select count(*) from orders where odate = 03-OCT-94 . 19. datewise. Select cname from cust where cname like A% or cname like B% . 18. Which day had the hightest total amount ordered. 21. snum.cnum = cust. Largest order taken by each salesperson.'Motika')). All customers serviced by peel or Motika. 23. 16. All orders except those with 0 or NULL value in amt field. orders where orders. Largest order taken by each salesperson with order value more than $3000.snum in ( select snum from salespeople where sname in 'Peel'. Select odate. amt. Select cname from cust. Count the number of different non NULL city values in customers table. max(amt) from orders group by odate. snum order by odate. . 17. Select each customer s smallest order. snum. Count all orders for Oct 3rd.15. Select odate. max(amt) from orders where amt > 3000 group by odate. All customers whose names begin with a letter from A to B. snum. Select onum from orders where amt != 0 or amt is not null. Select count(distinct city) from cust. cnum from orders where amt = (select max(amt) from orders) 22. Select odate. Count the number of salespeople currently listing orders in the order table.
cnum = cust.cnum. Name of all customers matched with the salespeople serving them. cname from orders. min(amt) from orders group by cnum. sname. cust where salespeople. Put the output in this form. First customer in alphabetical order whose name begins with G. (ie same city). Select 'For the city (' || city || ').snum. Select cname. amt * 0. Names of salesperson and customer for each order after the order number. 31.cnum and orders. Display the totals of orders for each day and place the results in descending order. count(onum) from orders group by odate order by count(onum).snum = salespeople.snum = salespeople. Assume that each salesperson has a 12% commission. 29. 26. 32. cust. the highest rating is : (' || max(rating) || ')' from cust group by city. salespeople where orders. Find highest rating in each city. Select odate. 25. 30. Produce order no. and amount of salesperson s commission for that order.12 from orders order by snum. cname from orders. Select sname. 33. 28. cname from salespeople. Select onum. snum.. salespeople where cust.Select cnum.city = cust. Select 'For ' || to_char(odate. salesperson no. Select onum. .snum.cnum = cust.city. All combinations of salespeople and customers who shared a city. Get the output like For dd/mm/yy there are ___ orders. sname from cust. Select min(cname) from cust where cname like G% . the highest rating is : (rating). cust where orders.. amt.'dd/mm/yy') || ' there are '|| count(*) || ' Orders' from orders group by odate. 27. For the city (city). Select onum. List each order number followed by the name of the customer who made the order.
39.a. Find all pairs of customers served by single salesperson.cname.cname.cname.snum and salespeople. Select cname. Find all pairs of customers having the same rating. Display all customers located in cities where salesman serres has customer.rating from cust a. orders where cust.snum in ( select snum from salespeople where sname = 'Serres')). Select a.cnum and a. b. b.snum = salespeople.cnum < b.cnum and orders. Policy is to assign three salesperson to each customers.cnum != b.cnum 36.snum = cust. Find all pairs of customers having the same rating.cnum = orders. cust b where a. salespeople where cust.snum = orders. 35.snum = salespeople. Produce all customer serviced by salespeople with a commission above 12%. Calculate the amount of the salesperson s commission on each order with a rating above 100. Select cname from cust .a. cust b where a. Select cname from cust where city = ( select city from cust.12 and cust. each pair coming once only. salespeople where rating > 100 and salespeople. 38. 40.snum and sname = 'Serres').snum and cust.cnum = orders.rating from cust a. Select cname. cust. cust where sname in ( select sname from salespeople where rownum <= 3) order by cname.rating and a. Select cname from cust where city in ( select city from cust.rating and a.cnum != b.cname. Select sname.rating = b. Select a.34. comm from cust. sname. sname from salespeople.snum. Display all such combinations.cnum 37. amt * comm from orders. salespeople where comm > 0.rating = b.cnum.
Select onum.onum > b.cnum and a. cust c where a. b. Extract all the orders of Motika. names that customers and eliminates duplicates. Produce all pairs of salespeople which are living in the same city. amt from orders a.snum and a. salespeople b. 42. Select cname. 43. Select a.snum and a. 44. All orders credited to the same salesperson who services Hoffman. Exclude combinations of salespeople with themselves as well as duplicates with the order reversed.onum from orders a.snum and a.snum = b. orders b. Select c. 45. sname. Select distinct a.sname from salespeople a.cname from cust a .rowid != b.cnum = b.snum = b. b.cnum = a.sname. a.city. cust c where a.onum and c. salespeople b where a.cnum.cust b where a.cnum and a.cname.rowid. city from cust where rating = (select rating from cust where cname = 'Hoffman') and cname != 'Hoffman'. Produce names and cities of all customers with the same rating as Hoffman. Select Onum from orders where snum = ( select snum from salespeople where sname = Motika ).city = b.cnum = c. cname.onum.snum > b.where snum in (select snum from cust group by snum having count(snum) > 1). Produce all pairs of orders by given customer.snum = ( select snum from orders where cnum = ( select cnum . 41.
Select max(b. Select cnum. Select comm from salespeople where snum in (select snum from cust where city = London ). 52. a. 46.cname). Select cnum. max(b. 47. Find all customers whose cnum is 1000 above the snum of serres. odate from orders where cnum = ( select cnum from cust where cname = Cisnerous ). Select onum. Count the customers with rating above San Jose s average. Obtain all orders for the customer named Cisnerous. cname from cust where cnum > ( select snum+1000 from salespeople where sname = 'Serres'). cnum from orders where cnum in (select cnum from cust where city = 'London').cnum from orders a. Extract commissions of all salespeople servicing customers in London. 50. (cnum)). 51. 49. All orders that are greater than the average for Oct 4. Select snum. 53. rating from cust where rating > ( select avg(rating) from cust where city = 'San Jose'). Select * from orders where amt > ( select avg(amt) from orders where odate = '03-OCT-94'). Produce the names and rating of all customers who have above average orders. cust b . (Assume you don t know his customer no. Find average commission of salespeople in london. 48. Find all orders attributed to salespeople servicing customers in london. Select avg(comm) from salespeople where city = London .rating).from cust where cname = 'Hoffman')).
snum.odate = b. Select sname. 55.cnum = b.cnum and a. Find the sums of the amounts from order table grouped by date. 58. 56. 57. Select cname from cust a. sum(amt) from orders a group by odate having sum(amt) > ( select max(amt) from orders b where a.cnum group by cnum). Find all orders with above average amounts for their customers.snum. cnum. select onum. cust b where a.sum(amt) from orders group by snum having sum(amt) > ( select max(amt) from orders). a. Find total amount in orders for each salesperson for whom this total is greater than the amount of the largest order in the table. Find names and numbers of all salesperson who have more than one customer.odate group by odate).cnum = b. Select snum. amt from orders a where amt > ( select avg(amt) from orders b where a. orders b where a.where a.cnum = b.cnum group by a. Find all customers with order on 3rd Oct.cnum = b. Select odate.snum from orders a. 54.snum != b. Check if the correct salesperson was credited with each sale.cnum) > ( select avg(count(cnum)) from orders group by cnum). .cnum.cnum and odate = 03-OCT-94 . Select onum. b. 59. snum from salespeople where snum in ( select snum from cust group by snum having count(snum) > 1 ). eliminating all those dates where the sum was not at least 2000 above the maximum amount. a.cnum having count(a.
61. Select snum from cust group by snum having count(*) > 1. Select snum.snum != b. Extract rows of all salespeople with more than one current order. Find salespeople number.rating = ( select max(rating) from cust b where a. Select cname from cust where cname in ( select cname from cust a. 62.city = b. Select a. Select snum from cust group by snum having count(*) = 1. who have multiple customers.60. 66. Find all salespeople who have customers in their cities who they don t service. Select * from cust where 2 < (select count(*) from cust where city = 'San Jose').snum. a. sname. Extract cnum.cnum.city). Find salespeople who serve only one customer. salespeople b where a.snum ). 64. Select snum. 65.cname and city from customer table if and only if one or more of the customers in the table are located in San Jose.) Select distinct cname from cust a. Find salespeople no. name and city who have multiple customers.city and a. ( Both way using Join and Correlated subquery. salespeople b where a. count(snum) from orders .snum != b.city and a. Find names and numbers of all customers with ratings equal to the maximum for their city. 63.city = b.cname from cust a where a.city = b. city from salespeople where snum in ( select snum from cust group by snum having count(*) > 1).
city and salespeople. Select all salespeople with customers located in their cities who are not assigned to them.snum = cust. (use Join).snum from cust b where b.rating = 300 and a.a.snum = b.city = cust. Select a.city and salespeople. Find all salespeople who have customers with a rating of 300.snum = cust. 71.snum). . 69.snum = b.snum from salespeople a where exists ( select b.snum). 70.snum = b.cnum. Select sname from salespeople where snum in ( select snum from cust where salespeople. cust b where b. sname from salespeople where exists ( select cnum from cust where salespeople.cnum = c.cnum.snum != cust.snum).rating = 300 and a.city = cust. Extract from customers table every customer assigned the a salesperson who currently has at least one other customer ( besides the customer being selected) with orders in order table.snum) order by a.city and salespeople. Find salespeople with customers located in their cities ( using both ANY and IN).cnum. Select a.cnum group by a. 67. Find all salespeople who have customers with a rating of 300. (use EXISTS) Select a. Select sname from salespeople where snum = any ( select snum from cust where salespeople. (use EXISTS). Select snum.snum) 68.cname) from orders a.snum having count(*) < ( select count(*) from orders b where a.city = cust.snum. cust c where a.snum from salespeople a.group by snum having count(snum) > 1. max(c.
snum and salespeople. Select customers who have a greater rating than any customer in rome. Select onum. 75. 74. Select all orders that had amounts that were greater that atleast one of the orders from Oct 6th. amt from orders where amt < any ( select amt from orders.snum = cust.cname).cnum = cust.snum = cust. (Both using ANY and without ANY) Select onum.72. .cname from cust a where city = 'Rome' and rating > ( select max(rating) from cust where city != 'Rome').cnum). cust where city = 'San Jose' and orders. Select onum. Select sname from salespeople where exists ( select cname from cust where salespeople.cnum). cust where city = 'San Jose' and orders. 73.cnum = cust. Find all salespeople for whom there are customers that follow them in alphabetical order. Find all orders with amounts smaller than any amount for a customer in San Jose. amt from orders where amt < ( select max(amt) from orders.sname < cust. (Using ANY and EXISTS) Select sname from salespeople where sname < any ( select cname from cust where salespeople.snum). amt from orders where odate != '06-oct-94' and amt > ( select min(amt) from orders where odate = '06-oct-94'). Select a.
rating > a. cust where city = London and orders.cnum = cust. 79. Select onum. sname from cust.snum). 77.city != 'Paris' and b.city and salespeople.snum. salespeople .snum). 80.snum = cust.76. Select all customers whose ratings are equal to or greater than ANY of the Seeres. Select sname from salespeople where snum = any ( select snum from cust where salespeople. salespeople where rating >= any ( select rating from cust where snum = (select snum from salespeople where sname = 'Serres')) and sname != 'Serres' and salespeople.snum(+) = cust. amt from orders where amt > any ( select amt from orders.rating).cnum). Find all salespeople and customers located in london. Select sname. ( Using both ALL and NOT EXISTS). Find all orders for amounts greater than any for the customers in London.city and salespeople. Select cname.city != cust. Select those customers whose ratings are higher than every customer in Paris. Select * from cust a where not exists ( select b.city != cust.rating from cust b where b. ( Both using ANY and ALL) Select sname from salespeople where snum in ( select snum from cust where salespeople.snum = cust. Find all salespeople who have no customers located in their city. 78. cname from cust. Select * from cust where rating > any (select rating from cust where city = 'Paris').
83. Select a.city and c.city. Those with a rating of 200 or greater will also have the words High Rating .snum = cust. Higher Rating from cust where rating >= 200 UNION Select cname. rating. indicating weather or not a given salesperson was matched to a customer in his city. cities.cname. Write command that produces the name and number of each salesperson and each customer with more than one current order.city != c.snum = c. 84.odate from orders a.b. 82.city = 'London' and salespeople.city = cust.city)). min(amt) from orders group by snum). Select cname. Append strings to the selected fields. dates on which highest and lowest orders were brought. salespeople b where a. a. 'Customer Present' from salespeople a where exists ( select snum from cust where a. Select a. 'Customer Not Present' from salespeople a where exists ( select snum from cust c where a.snum and a. 81.snum. rating. city. Create a union of two queries that shows the names.snum. cities.amt.snum = b. b.snum and a. For every salesperson.odate. Select 'Customer Number ' || cnum "Code ". orders b where (a. Put the result in alphabetical order. Lower Rating from cust where rating < 200.snum and a.snum not in ( select snum from cust where a.count(*) . cities and ratings of all customers.'Matched'.'Not Matched') from cust a. city.city = cust. Select snum.city.where cust.city = 'London' and cust. b. decode(a. while the others will have the words Low Rating .amt.city) UNION select snum.amt.snum = salespeople.amt) in (select max(amt). 85. b.snum = cust. List all of the salespeople and indicate those who don t have customers in their cities as well as those who do have.
city = 'London') and city = 'London'. Produce all the salesperson in London who did not have customers there. 87. Retain duplicates between the last two queries.snum = salespeople. 3. 89. Have the first select the snums of all salespeople in San Jose.snum = salespeople. then second the cnums of all customers in San Jose and the third the onums of all orders on Oct. 88. sname from salespeople where snum in ( select snum from cust where cust. cname from cust. salespeople . Produce all the salesperson in London who had at least one customer there. Select 'Customer Number ' || cnum "Code " from cust where city = 'San Jose' UNION select 'Salesperson Number '||snum from salespeople where city = 'San Jose' UNION ALL select 'Order Number '|| onum from Orders where odate = '03-OCT-94'.snum and cust. We want to see salespeople matched to their customers without excluding those salesperson who were not currently assigned to any customers.city = 'London') and city = London .count(*) from orders group by snum having count(*) > 1. Select snum. (User OUTER join and UNION) Select sname. Form a union of three queries. sname from salespeople where snum in ( select snum from cust where cust.from orders group by cnum having count(*) > 1 UNION select 'Salesperson Number '||snum.snum and cust. but eliminates and redundancies between either of them and the first. Select snum. 86.
where cust. salespeople where 0 = (select count(*) from cust where cust.snum(+) = salespeople. Select sname. .snum).snum UNION select distinct sname. salespeople where cust. cname from cust. 'No Customer' from cust.snum = salespeople.snum = salespeople.snum.