Page no.

TABLE SALESPEOPLE SNUM 1001 1002 1004 1007 1003 TABLE CUST CNUM 2001 2002 2003 2004 2006 2007 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 CNUM 03-OCT-94 2008 03-OCT-94 2001 03-OCT-94 2007 03-OCT-94 2003 04-OCT-94 2008 04-OCT-94 2002 05-OCT-94 2004 05-OCT-94 2006 06-OCT-94 2004 06-OCT-94 2006 SNUM 1001 1004 1002 1007 1003 1001 1002 1001 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 SNAME Peel Serres Motika Rafkin Axelrod CITY London San Jose London Barcelona New york .12 .11 .15 .1 .13 COMM

1 of 15

1007

1002

Problems : 1. 2. 3. Display snum,sname,city and comm of all salespeople. Select snum, sname, city, comm from salespeople; Display all snum without duplicates from all orders. Select distinct snum from orders; Display names and commissions of all salespeople in london. Select sname,comm from salespeople where city = ‘London’; All customers with rating of 100. Select cname from cust where rating = 100;

4.

5.

Produce orderno, amount and date form all rows in the order table. Select ordno, amt, odate from orders;
Suresh Babu

All customers who were either located in San Jose or had a rating above 200. All orders for more than $1000.cnum and orders. 16. (Boundary values should be excluded) Select sname. Select sname. All customers with NULL values in city column. All customers serviced by peel or Motika.12. Select * from orders where odate in (‘03-OCT-94’. city from salespeople where city in (‘Barcelona’. All customers in San Jose. 9. orders where orders. Suresh Babu . 14. Select cname from cust. 12. 8.'Motika')). who have rating more than 200.’London’).’04-OCT-94’). All salespeople with commission between 0.snum in ( select snum from salespeople where sname in 'Peel'.10 and comm < 0. Select cname from cust where city is null.12. 10. Names and citires of all salespeople in london with commission above 0.Page no.10.10 and 0. 2 of 15 6. 7. Rome.cnum = cust. All customers excluding those with rating <= 100 unless they are located in Select cname from cust where rating <= 100 or city = ‘Rome’. All customers whose names begin with a letter from A to B. Select cname from cust where rating > 200. city from salepeople where comm > 0. 11. All salespeople either in Barcelona or in london. Select * from orders where amt > 1000. All orders taken on Oct 3Rd and Oct 4th 1994. comm from salespeople where comm > 0. Select sname. 15. Select cname from cust where city = ‘San Jose’ or rating > 200.10 and city = ‘London’. 13.

26. Select onum from orders where amt != 0 or amt is not null. Select each customer’s smallest order. 20. Largest order taken by each salesperson. snum order by odate. snum order by odate.'dd/mm/yy') || ' there are '|| count(*) || ' Orders' from orders group by odate. 24. Select count(*) from orders where odate = ‘03-OCT-94’. 22. Select odate. max(amt) from orders where amt > 3000 group by odate. 23. amt. Select cnum.snum. Largest order taken by each salesperson with order value more than $3000. 25. cnum from orders where amt = (select max(amt) from orders) Count all orders for Oct 3rd. Select count(distinct snum) from orders. Count the number of different non NULL city values in customers table. 18. Count the number of salespeople currently listing orders in the order table. 19. Select min(cname) from cust where cname like ‘G%’. Select odate. Which day had the hightest total amount ordered.snum.Page no. 3 of 15 17. Select cname from cust where cname like ‘A%’ or cname like ‘B%’. snum. max(amt) from orders group by odate. Select count(distinct city) from cust. Select odate. snum. Suresh Babu . datewise. All orders except those with 0 or NULL value in amt field. min(amt) from orders group by cnum. First customer in alphabetical order whose name begins with G. Select 'For ' || to_char(odate. Get the output like “ For dd/mm/yy there are ___ orders. snum. 21.

amt * 0. (ie same city).snum = orders. Select odate. Calculate the amount of the salesperson’s commission on each order with a rating above 100. Select sname.cnum and orders.snum and Suresh Babu .cnum = cust. salespeople where comm > 0. Select onum. cust.cnum. Select onum. 33. and amount of salesperson’s commission for that order. sname. Put the output in this form. 32.. Name of all customers matched with the salespeople serving them. Produce order no. sname. 34. salespeople where rating > 100 and salespeople. cname from orders.snum = salespeople. Assume that each salesperson has a 12% commission.snum = cust.snum.snum and salespeople. 28.cnum = cust. Display the totals of orders for each day and place the results in descending order.snum = salespeople. salesperson no. Select sname. the highest rating is : (' || max(rating) || ')' from cust group by city.Page no. amt. Names of salesperson and customer for each order after the order number. All combinations of salespeople and customers who shared a city. sname from cust. cust where orders. 30. Find highest rating in each city.city. Produce all customer serviced by salespeople with a commission above 12%. 35.12 from orders order by snum. the highest rating is : (rating). cust where salespeople.city = cust. 29. For the city (city). Select cname.snum.snum = salespeople. comm from cust..snum. 4 of 15 27.12 and cust. count(onum) from orders group by odate order by count(onum). Select 'For the city (' || city || '). Select cname. salespeople where cust. List each order number followed by the name of the customer who made the order. 31. cname from salespeople. cname from orders. amt * comm from orders. salespeople where orders. Select onum. snum. cust.

cname.sname Suresh Babu . Select a.rowid != b.cname.rating and a.cnum Find all pairs of customers having the same rating.Page no. sname from salespeople.cname from cust a . Display all customers located in cities where salesman serres has customer.cnum = orders.rating from cust a. cust where sname in ( select sname from salespeople where rownum <= 3) order by cname. Select cname from cust where snum in (select snum from cust group by snum having count(snum) > 1). cust b where a.snum = salespeople.cnum.snum = b. cust b where a.rating = b. Select a. Display all such combinations.a. 40. 38. Select distinct a. 5 of 15 36. b. salespeople where cust. each pair coming once Select a.rating from cust a. only. Select cname from cust where city = ( select city from cust.rating = b.cnum != b.rating and a.cnum and a.cname. Exclude combinations of salespeople with themselves as well as duplicates with the order reversed.a.snum in ( select snum from salespeople where sname = 'Serres')). 41. 39.cnum < b.sname. orders where cust. Find all pairs of customers served by single salesperson.cnum != b. b. Select cname from cust where city in ( select city from cust.cnum Find all pairs of customers having the same rating. b.cust b where a.rowid.cnum and orders. Policy is to assign three salesperson to each customers. Select cname.cnum = orders.snum and a.cname. Produce all pairs of salespeople which are living in the same city. 37.snum and sname = 'Serres'). cust.

snum and a.cnum = a.snum = b. 43. cust c where a.onum.snum > b. Select cname.city = b. names that customers and eliminates duplicates. Select snum.cnum and a. All orders that are greater than the average for Oct 4.onum from orders a. cust c where a. Extract all the orders of Motika.cnum = b.cname. 44. 46.snum and a. b. city from cust where rating = (select rating from cust where cname = 'Hoffman') and cname != 'Hoffman'. Find all orders attributed to salespeople servicing customers in london. salespeople b where a. orders b. Select onum.onum > b. a. All orders credited to the same salesperson who services Hoffman. 6 of 15 from salespeople a. cnum from orders where cnum in (select cnum from cust Suresh Babu .Page no. sname.onum and c. Produce all pairs of orders by given customer. Select * from orders where amt > ( select avg(amt) from orders where odate = '03-OCT-94'). Select Onum from orders where snum = ( select snum from salespeople where sname = ‘Motika’). Find average commission of salespeople in london. cname. 48. Select c. 42. 47.cnum and a. salespeople b.snum = ( select snum from orders where cnum = ( select cnum from cust where cname = 'Hoffman')).city. Select avg(comm) from salespeople where city = ‘London’.cnum = c. Produce names and cities of all customers with the same rating as Hoffman. amt from orders a.cnum. 45.

cnum from orders a. cust b where a. Select cnum. Select snum. 7 of 15 where city = 'London'). Count the customers with rating above San Jose’s average. Find total amount in orders for each salesperson for whom this total is greater than the amount of the largest order in the table. rating from cust where rating > ( select avg(rating) from cust where city = 'San Jose').cnum = b. Select onum.cnum) > ( select avg(count(cnum)) from orders group by cnum). Select comm from salespeople where snum in (select snum from cust where city = ‘London’). max(b. Select cnum. (cnum)). 52.cnum and odate = ‘03-OCT-94’. Extract commissions of all salespeople servicing customers in London.cname). Find all customers with order on 3rd Oct. Find all customers whose cnum is 1000 above the snum of serres. 50. 51. odate from orders where cnum = ( select cnum from cust where cname = ‘Cisnerous’). Select sname. cname from cust where cnum > ( select snum+1000 from salespeople where sname = 'Serres'). Select max(b. (Assume you don’t know his customer no. snum from salespeople where snum in ( select snum Suresh Babu .cnum having count(a.cnum = b. a. orders b where a.sum(amt) from orders group by snum having sum(amt) > ( select max(amt) from orders). 49. Find names and numbers of all salesperson who have more than one customer.rating). 55. Obtain all orders for the customer named Cisnerous.cnum group by a. Select cname from cust a. Produce the names and rating of all customers who have above average orders. 54. 53.Page no. 56.

snum != b. cnum.cnum and a.city and a.snum from orders a. Check if the correct salesperson was credited with each sale.cnum.city). salespeople b where a. Select a.snum != b. 58.city = b.city = b.cnum = b.snum. Select cname from cust where cname in ( select cname from cust a. Find names and numbers of all customers with ratings equal to the maximum for their city. Extract cnum.cnum = b.cname from cust a where a. select onum. 62. Select onum. 59. a.snum ).Page no. eliminating all those dates where the sum was not at least 2000 above the maximum amount. Find all orders with above average amounts for their customers.snum. a. Suresh Babu . Select odate. Select * from cust where 2 < (select count(*) from cust where city = 'San Jose'). 60. a. 8 of 15 from cust group by snum having count(snum) > 1 ).rating = ( select max(rating) from cust b where a. 57.cnum group by cnum).cname and city from customer table if and only if one or more of the customers in the table are located in San Jose. Find the sums of the amounts from order table grouped by date.city and a. 61.snum.odate = b. sum(amt) from orders a group by odate having sum(amt) > ( select max(amt) from orders b where a.cnum. cust b where a. amt from orders a where amt > ( select avg(amt) from orders b where a.) Select distinct cname from cust a.odate group by odate). Find all salespeople who have customers in their cities who they don’t service.snum != b. salespeople b where a.city = b. ( Both way using Join and Correlated subquery. b.

(use EXISTS). count(snum) from orders group by snum having count(snum) > 1. Select snum from cust group by snum having count(*) = 1. 66. city from salespeople where snum in ( select snum from cust group by snum having count(*) > 1). cust b where b. Select a. Select snum. Find all salespeople who have customers with a rating of 300.snum.cnum = c. name and city who have multiple customers.rating = 300 and a. (use Join).snum = b. 70. Select all salespeople with customers located in their cities who are not assigned to them. Find salespeople who serve only one customer. sname from salespeople where exists ( select cnum from cust where salespeople.snum != cust.city and salespeople. Find all salespeople who have customers with a rating of 300. 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. 67. 65.rating = 300 and a. 64. who have multiple customers. Find salespeople number. sname. Select a.snum from salespeople a. 9 of 15 63. cust c where a.cnum. Extract rows of all salespeople with more than one current order. (use EXISTS) Select a. 69. Select snum.cnum Suresh Babu .snum) 68. max(c.snum from cust b where b. Find salespeople no.snum from salespeople a where exists ( select b.snum = b.Page no.cname) from orders a. Select snum from cust group by snum having count(*) > 1. Select snum.city = cust.snum).

Page no.snum = cust.snum).snum = cust. Find salespeople with customers located in their cities ( using both ANY and Select sname from salespeople where snum in ( select snum from cust where salespeople. (Using ANY and EXISTS) Select sname from salespeople where sname < any ( select cname from cust where salespeople. Select sname from salespeople where exists ( select cname from cust where salespeople. Select customers who have a greater rating than any customer in rome.a.snum) order by a.snum having count(*) < ( select count(*) from orders b where a.city = cust. IN). 10 of 15 71. (Both using ANY and without ANY) Select onum.snum and salespeople. Select a. amt Suresh Babu . Find all orders with amounts smaller than any amount for a customer in San Jose.snum). 75. 73.snum).cname). 74. Find all salespeople for whom there are customers that follow them in alphabetical order.city and salespeople. Select all orders that had amounts that were greater that atleast one of the orders from Oct 6th. Select onum.cnum.city and salespeople.sname < cust.snum = b.city = cust. 72.snum = cust.snum = cust. amt from orders where odate != '06-oct-94' and amt > ( select min(amt) from orders where odate = '06-oct-94'). Select sname from salespeople where snum = any ( select snum from cust where salespeople.cname from cust a where city = 'Rome' and rating > ( select max(rating) from cust where city != 'Rome'). group by a.cnum.

cust where city = 'San Jose' and orders. Find all salespeople who have no customers located in their city.Page no. Select all customers whose ratings are equal to or greater than ANY of the 77.snum(+) = cust.cnum). Select * from cust a where not exists ( select b. Select * from cust where rating > any (select rating from cust where city = 'Paris'). 76. Suresh Babu .city != 'Paris' and b. Select onum. ( Using both ALL and NOT EXISTS). salespeople where rating >= any ( select rating from cust where snum = (select snum from salespeople where sname = 'Serres')) and sname != 'Serres' and salespeople.cnum = cust. Select those customers whose ratings are higher than every customer in Paris. 11 of 15 from orders where amt < any ( select amt from orders.rating).rating from cust b where b. Seeres. Select sname from salespeople where snum = any ( select snum from cust where salespeople.snum.city and salespeople.cnum = cust.snum).snum = cust.cnum). ( Both using ANY and ALL) Select sname from salespeople where snum in ( select snum from cust where salespeople. sname from cust.city != cust. cust where city = 'San Jose' and orders. Select cname. amt from orders where amt < ( select max(amt) from orders.snum = cust.city != cust.rating > a.snum). 78.city and salespeople.

snum and a. indicating weather or not a given salesperson was matched to a customer in his city.city and c. amt from orders where amt > any ( select amt from orders. a. Find all orders for amounts greater than any for the customers in London. 84. Select a.city = cust.snum = c.odate from orders a. b.b.amt.city != c.city) UNION select snum. Find all salespeople and customers located in london. salespeople b where a. orders b where (a. 80. city. cust where city = ‘London’ and orders.city = cust. cities.'Not Matched') from cust a. Select a. while the others will have the words ‘Low Rating’.snum not in ( select snum from cust where a. List all of the salespeople and indicate those who don’t have customers in their cities as well as those who do have.snum = cust. salespeople where cust. For every salesperson.snum = cust.cname. min(amt) from orders group by snum).snum and a.snum. 'Customer Not Present' from salespeople a where exists ( select snum from cust c where a.city = 'London' and cust. Select cname. dates on which highest and lowest orders were brought. Select sname. 82.snum = b.city)).odate. Select snum.amt.cnum). Create a union of two queries that shows the names.amt. 81.city.snum. Those with a rating of 200 or greater will also have the words ‘High Rating’. city. b. rating. b. cname from cust.snum and a.city.snum = salespeople. 'Customer Present' from salespeople a where exists ( select snum from cust where a.cnum = cust. ‘Higher Rating’ from cust where rating >= 200 UNION Suresh Babu . 12 of 15 79. 83.city = 'London' and salespeople. Append strings to the selected fields. decode(a.amt) in (select max(amt). Select onum.'Matched'.Page no. cities and ratings of all customers.

87. cities. Select snum. sname from salespeople where snum in ( select snum from cust where cust. Produce all the salesperson in London who had at least one customer there. Put the result in alphabetical order. rating. Select snum.city = 'London') and city = ‘London’. Form a union of three queries. Write command that produces the name and number of each salesperson and each customer with more than one current order. (User OUTER join and UNION) Suresh Babu . Select 'Customer Number ' || cnum "Code ".snum = salespeople. then second the cnums of all customers in San Jose and the third the onums of all orders on Oct. Retain duplicates between the last two queries.count(*) from orders group by cnum having count(*) > 1 UNION select 'Salesperson Number '||snum. 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'. 88. Have the first select the snums of all salespeople in San Jose.count(*) from orders group by snum having count(*) > 1. but eliminates and redundancies between either of them and the first.snum and cust. 85. 89. sname from salespeople where snum in ( select snum from cust where cust. Produce all the salesperson in London who did not have customers there.Page no. 86. We want to see salespeople matched to their customers without excluding those salesperson who were not currently assigned to any customers. 13 of 15 Select cname.snum = salespeople.city = 'London') and city = 'London'. ‘Lower Rating’ from cust where rating < 200.snum and cust. 3.

Page no.snum = salespeople. salespeople where cust. 14 of 15 Select sname. Select sname. Suresh Babu . salespeople where cust.snum(+) = salespeople.snum = salespeople. 'No Customer' from cust.snum).snum UNION select distinct sname. cname from cust. cname from cust.snum. salespeople where 0 = (select count(*) from cust where cust.

Sign up to vote on this title
UsefulNot useful