Sei sulla pagina 1di 40

EXERCISE 1

Q.1 Create Table salespeople with fields snum, sname, city, commision.
create table salespeople11
(
s_no number(30) primary key,
s_name varchar2(20),
city_name varchar2(20),
commission number(30)
);

create table customer11


(
c_no number(30) primary key,
c_name varchar2(20),
city_name varchar2(20),
rating number(30),
s_no number(30)
);

create table orders11


(
o_no number primary key,
o_date date,
amount number(30),
s_no number
);

create table cso11


(
s_no number(30) REFERENCES salespeople11,
c_no number(30) REFERENCES customer11,
o_no number REFERENCES orders11,
CONSTRAINT DG PRIMARY KEY(s_no,c_no,o_no)
);

SQL> desc salespeople;


Name

Null? Type

----------------------------------------- -------- ---------------------------S_NO

NOT NULL NUMBER(30)

S_NAME

VARCHAR2(20)

CITY_NAME

VARCHAR2(20)

COMMISSION

NUMBER

SQL> desc customer1;


Name

Null? Type

----------------------------------------- -------- ---------------------------C_NO


C_NAME
CITY_NAME
RATING
S_NO

NOT NULL NUMBER(30)


VARCHAR2(20)
VARCHAR2(20)
NUMBER(30)
NUMBER(30)

SQL> desc orders;


Name

Null? Type

----------------------------------------- -------- ---------------------------O_NO


O_DATE
AMOUNT
S_NO
CBALL

NOT NULL NUMBER


DATE
NUMBER(30)
NUMBER
NUMBER(30)

SQL> desc cso;


Name

Null? Type

----------------------------------------- -------- ---------------------------S_NO

NOT NULL NUMBER(30)

C_NO

NOT NULL NUMBER(30)

O_NO

NOT NULL NUMBER

EXERCISE 2
1. Add at least 10 records
SQL>
INSERT INTO salespeople VALUES(1,'akshay','indapur',100);
INSERT INTO salespeople VALUES(2,'akshta','indapur',200);
INSERT INTO salespeople VALUES(3,'amol','pune',300);
INSERT INTO salespeople VALUES(4,'aanand','thane',400);
INSERT INTO salespeople VALUES(5,'vijay','nashik',500);
INSERT INTO salespeople VALUES(6,'reshma','indapur',600);
INSERT INTO salespeople VALUES(7,'rekha','indapur',700);
INSERT INTO salespeople VALUES(8,'ashwini','aajoti',800);
INSERT INTO salespeople VALUES(9,'priyanka','baramati',900);
INSERT INTO salespeople VALUES(10,'sushma','akluj',1000);
INSERT INTO salespeople VALUES(11,'sujata','mumbai',2000);
INSERT INTO salespeople VALUES(12,'vinod','indapur',3000);
INSERT INTO salespeople VALUES(13,'santosh','mumbai',4000);
INSERT INTO salespeople VALUES(14,'mahesh','barshi',5000);
INSERT INTO salespeople VALUES(15,'allen','mumbai',6000);
INSERT INTO salespeople VALUES(16,'rutuja','karmala',7000);
INSERT INTO salespeople VALUES(17,'suyog','pune',8000);
INSERT INTO salespeople VALUES(18,'sunita','dound',9000);
INSERT INTO salespeople VALUES(19,'suraj','pimpry',10000);
INSERT INTO salespeople VALUES(20,'rahul','tembhurni',11000);

2. Display all the records with all sales peoples information.


SQL> select * from salespeople;
S_NO
----------

S_NAME
--------------------

CITY_NAME

COMMISSION

--------------------

----------

akshay

indapur

100

akshta

indapur

200

amol

pune

300

aanand

thane

vijay

nashik

reshma

indapur

600

rekha

indapur

700

ashwini

aajoti

priyanka

baramati

900

10

sushma

akluj

1000

11

sujata

akole

2000

12

vinod

indapur

3000

13

santosh

bhigvan

4000

14

mahesh

barshi

5000

15

allen

mumbai

6000

16

rutuja

karmala

7000

17

suyog

thane

8000

18

sunita

dound

9000

19

suraj

pimpry

10000

20

rahul

tembhurni

400
500

800

11000

SQL> select * from customer1;

C_NO
----------

C_NAME

CITY_NAME

--------------------

RATING

--------------------

----------

S_NO
----------

sonali

indapur

10

sreya

pune

20

allen

karmala

20

josef

thane

40

soham

solapur

30

sayali

jeur

50

priya

barshi

10

jiya

nashik

40

sushma

nagar

10

sagar

kem

11

bankat

mohol

60

70

10

80

11

10

12

12

sujata

dound

13

sudha

pimpry

20

13

14

sadhna

bhigvan

30

14

15

megha

narhe

16

chetna

pathardy

100

16

17

reshma

baramati

50

17

18

ashwini

akluj

19

rutuja

latur

40

19

20

vijay

swarget

60

20

20 rows selected.

90

70

15

18

3. Display the details of fields sname, commission


SQL> select s_name,commission from salespeople;
S_NAME
-------------------akshay
akshta
amol
aanand
vijay
reshma
rekha
ashwini
priyanka
sushma
sujata
vinod
santosh
mahesh
allen
rutuja
suyog
sunita
suraj
rahul
20 rows selected.

COMMISSION
---------100
200
300
400
500
600
700
800
900
1000
2000
3000
4000
5000
6000
7000
8000
9000
10000
11000

4. Display the odate, snum, onum, amt from orders table.


SQL> select * from orders;

O_NO
----------

O_DATE
---------

AMOUNT

S_NO

----------

----------

02-MAR-12

1000

03-MAR-12

2000

05-MAR-12

200

06-MAR-12

4000

10-MAR-12

300

12-MAR-12

5000

21-MAR-12

500

22-MAR-12

400

23-MAR-12

100

10 24-MAR-12

600

10

10 rows selected.

5. Display snum from orders table without duplications.


SQL> select distinct(s_no)from orders;
S_NO
---------1
6
11
13
2
14
20
4
5
8
17
3
7
18
9
10
12
15
16
19

6. Display name & city of salesman where city is "Pune


SQL> select s_name,city_name from salespeople where city_name='pune'

S_NAME

CITY_NAME

-------------------- -------------------amol

pune

7. Display all details of customer where rating is 100


SQL> select * from customer1 where rating=100;

C_NO C_NAME

CITY_NAME

RATING

S_NO

---------- -------------------- -------------------- ---------- ---------16 chetna

pathardy

100

16

8. Display all details from customer table where salespersons number is


1001.
SQL> select * from customer1 where s_no=18;
C_NO C_NAME

CITY_NAME

RATING

---------- -------------------- -------------------- ---------- ---------18 ashwini

akluj

70

18

S_NO

9. Display the numbers of sales persons, with orders currently in the orders
table without any repeats.
SQL> select count(s_no) from orders where o_date=(select max(o_date) from orders
);
COUNT(S_NO)
----------3

10. Display all customers where rating is more than 200


SQL> select * from customer1 where rating>50;
C_NO
----------

C_NAME
--------------------

9 sushma

CITY_NAME

RATING

-------------------- ---------nagar

S_NO
----------

60

10 sagar

kem

11 bankat

mohol

80

11

15 megha

narhe

90

15

16 chetna

pathardy

100

18 ashwini

akluj

70

20 vijay

7 rows selected.

swarget

70

10

60

16
18
20

12. Display all customers where city is either 'Pune' or 'Mumbai'


SQL> select * from customer1 where city_name='pune'or city_name= 'mumbai';
C_NO
---------2

C_NAME

CITY_NAME

-------------------sreya

RATING

-------------------- ---------pune

20

S_NO
---------2

SQL> select rating from customer1 where rating BETWEEN 50 AND 100;

RATING
---------50
60
70
80
90
100
50
70
60

SQL> select DISTINCT s_no from orders;


S_NO
---------1
6
11
13
2
14
20
4
5
8
17
S_NO
---------3
7
18
9
10
12
15
16
19

SQL> select * from customer1 where city_name BETWEEN 'pune' AND 'thane';

C_NO
---------2
4

C_NAME

CITY_NAME

--------------------

RATING

--------------------

sreya

---------- ----------

pune

josef

soham

20

vijay

S_NO

20

thane

40

solapur

30

swarget

60

20

13. List all customers not having city 'Pune' or rating more than 100

SQL> select * from customer1 where city_name!='pune' or rating >100;


C_NO C_NAME

CITY_NAME

RATING

S_NO

---------- -------------------- -------------------- ---------- ---------1

sonali

allen

indapur

10

karmala

20

thane

40

josef

soham

solapur

30

sayali

jeur

50

priya

barshi

jiya

nashik

40

sushma

nagar

60

10

sagar

kem

70

10

11

bankat

mohol

80

11

12

sujata

dound

5
6

10

10

12

C_NO C_NAME

CITY_NAME

RATING

S_NO

---------- -------------------- -------------------- ---------- ---------13 sudha

pimpry

20

13

14 sadhna

bhigvan

30

14

15 megha

narhe

90

15

16 chetna

pathardy

100

16

17 reshma

baramati

50

17

18 ashwini

akluj

70

19 rutuja

latur

40

20 vijay

swarget

18
19

60

SQL> select * from customer1 where city_name!='pune' AND rating>50;

C_NO C_NAME

CITY_NAME

RATING

S_NO

---------- -------------------- -------------------- ---------- ---------9 sushma


10 sagar

nagar
kem

60
70

9
10

11 bankat

mohol

80

11

15 megha

narhe

90

15

16 chetna

pathardy

100

18 ashwini

akluj

70

18

swarget

60

20

20 vijay

16

7 rows selected.

14. List all orders between order dates 10/03/05 to 30/3/05


SQL> select * from orders where o_date BETWEEN '10-march-2012' AND '30-march2012';

O_NO O_DATE

AMOUNT

S_NO

---------- --------- ---------- ---------5 10-MAR-12

300

6 12-MAR-12

5000

7 21-MAR-12

500

8 22-MAR-12

400

9 23-MAR-12

100

10 24-MAR-12

600

10

11 26-MAR-12

7000

11

12 28-MAR-12

700

12

5. Display all orders more that 1000 amt.


SQL> select * from orders where amount>1000;

O_NO O_DATE

AMOUNT

S_NO

---------- --------- ---------- ---------2 03-MAR-12

2000

4 06-MAR-12

4000

6 12-MAR-12

5000

11 26-MAR-12

7000

11

13 05-FEB-12

8000

13

14 07-FEB-12

9000

14

17 04-JUN-12

2000

17

18 09-FEB-12

6000

18

SQL> select * from orders where amount>500;


O_NO O_DATE

AMOUNT

S_NO

---------- --------- ---------- ---------1 02-MAR-12

1000

2 03-MAR-12

2000

4 06-MAR-12

4000

6 12-MAR-12

5000

10 24-MAR-12

600

10

11 26-MAR-12

7000

11

12 28-MAR-12

700

12

13 05-FEB-12

8000

13

14 07-FEB-12

9000

14

800

15

15 02-MAR-12
16 05-APR-12

900

16

16. Display names & cities of all salespeople in 'Pune' with a commission
above
SQL> select s_name,city_name from salespeople where city_name='indapur' AND com
mission>100;

S_NAME

CITY_NAME

-------------------- -------------------akshta

indapur

reshma

indapur

rekha

indapur

vinod

Indapur

17. Display all customers excluding those, with rating less than equal to
100, unless they are located in 'Nagar'

SQL> select * from customer1 where rating>100 or city_name='nagar';

C_NO C_NAME

CITY_NAME

RATING

S_NO

---------- -------------------- -------------------- ---------- ---------9 sushma

nagar

60

18. Display all sales persons names starting with character 'G'
SQL> select * from salespeople where s_name Like 's%';
S_NO S_NAME

CITY_NAME

COMMISSION

---------- -------------------- -------------------- ---------10 sushma


11 sujata

akluj
akole

1000
2000

13 santosh

bhigvan

4000

17 suyog

thane

8000

18 sunita

dound

9000

19 suraj

pimpry

10000

19. Display all sales persons names starting with character 'G', the 4th
character is 'A' & the rest of characters will be any.

SQL> select s_no,s_name,city_name,commission


2

from salespeople

where s_name like 's____a%';


S_NO S_NAME

CITY_NAME

COMMISSION

---------- -------------------- -------------------- ---------10 sushma

akluj

11 sujata

akole

18 sunita

dound

1000
2000
9000

20. Find all records from customers table where city is not known i.e.
NULL.
SQL> select c_no,c_name,city_name,rating
2 from customer1
3 where city_name is null;

no rows selected

21. Display all the customer's names begins with a letter A to G


SQL> select s_no,s_name,city_name,commission
2

from salespeople

where s_name like 's____a%';


S_NO S_NAME

CITY_NAME

COMMISSION

---------- -------------------- -------------------- ---------10 sushma

akluj

11 sujata

akole

18 sunita

dound

1000
2000
9000

22. Assume each salesperson has a 12% commission on order amt. Display
orderno, snum, commission for that order.
SQL> select o_no,s_no,(amount*12)/100 commission from orders;

O_NO

S_NO COMMISSION

---------- ---------- ---------1

120

240

24

480

36

600

60

48

12

10

10

72

11

11

840

O_NO

S_NO COMMISSION

---------- ---------- ---------12

12

84

13

13

960

14

14

1080

15

15

96

16

16

108

17

17

240

18

18

720

19

19

72

20

20

48

SQL> select * from customer1 where rating<=100;


C_NO C_NAME

CITY_NAME

RATING

---------- -------------------- -------------------- ---------- ---------1 sonali

indapur

10

S_NO

2 sreya

pune

3 allen

karmala

4 josef

thane

5 soham

20

20
40

solapur

3
4

30

6 sayali

jeur

7 priya

barshi

10

8 jiya

nashik

40

9 sushma
10 sagar
11 bankat

50

nagar

60

kem

70

mohol

C_NO C_NAME

9
10

80

11

CITY_NAME

RATING

---------- -------------------- -------------------- ---------- ---------12 sujata

dound

10

13 sudha

pimpry

20

13

14 sadhna

bhigvan

30

14

15 megha

narhe

90

12

15

16 chetna

pathardy

100

16

17 reshma

baramati

50

17

18 ashwini

akluj

19 rutuja

latur

20 vijay

swarget

70
40
60

18
19
20

S_NO

EXERCIZE 3
1)Display all the customers' records, arranged on name.
SQL> select * from customer1 order by c_name
C_NO C_NAME

CITY_NAME

RATING

---------- -------------------- -------------------- ---------- ---------3 allen

karmala

20

70

18

18 ashwini

akluj

11 bankat

mohol

80

16 chetna

pathardy

100

11
16

8 jiya

nashik

40

4 josef

thane

40

15 megha
7 priya
17 reshma
19 rutuja
14 sadhna
12 sujata
9 sushma
20 vijay

20 rows selected.

narhe
barshi

90
10

baramati
latur
bhigvan

15
7

50
40

17
19

30

14

dound

10

12

nagar

60

swarget

60

20

S_NO

2. Display all customers records arranged on rating in desc. Order.


SQL> select * from customer1 ORDER BY rating DESC;
C_NO C_NAME

CITY_NAME

RATING

S_NO

---------- -------------------- -------------------- ---------- ---------16 chetna

pathardy

100

16

15 megha

narhe

90

15

11 bankat

mohol

80

11

10 sagar

70

10

akluj

70

18

swarget

60

20

9 sushma

nagar

60

17 reshma

baramati

18 ashwini
20 vijay

6 sayali

kem

50

17

jeur

50

8 jiya

nashik

40

4 josef

thane

40

3. Display all sales persons records arranged on snum


SQL> select * from salespeople order by s_no;
S_NO S_NAME

CITY_NAME

COMMISSION

---------- -------------------- -------------------- ---------1 akshay

indapur

100

2 akshta

indapur

200

3 amol

pune

4 aanand
5 vijay
6 reshma
7 rekha
8 ashwini

thane
nashik
indapur

300
400
500
600

indapur

700

aajoti

800

4. Display the count for total number of customers in customers table.


SQL> select DISTINCT COUNT(s_no) from orders;
COUNT(S_NO)
----------20

5. Display the count of snum in order table without duplication of snum.


SQL> select DISTINCT COUNT(s_no) from orders;
COUNT(S_NO)
----------20

6. Display the counts of all orders for Feb05


SQL> select COUNT(o_no) from orders where o_date='5-feb-2012';

COUNT(O_NO)
----------1

8. Display the maximum outstanding amount as blnc+amt


SQL> select max(amount)"blnc+amount" from orders;
blnc+amount
----------9000

9. Display the minimum rating within customers table.


SQL> select MIN(rating) from customer1;
MIN(RATING)
----------10

10. Display average of amt.


SQL> select AVG(amount) from orders;

AVG(AMOUNT)
----------2475

11. Display sales persons number wise maximum amt from order table.
SQL> select s_no from orders where amount=(select MAX(amount)from orders);
S_NO
---------14

12. Display the largest order taken by each salesperson on each date.
select o_no,o_date,s_no, max(amount) from orders
group by o_no,o_date,s_no
having max(amount)>5000;

O_NO O_DATE

S_NO MAX(AMOUNT)

---------- --------- ---------- ----------11 26-MAR-12

11

7000

18 09-FEB-12

18

6000

14 07-FEB-12

14

9000

13 05-FEB-12

13

8000

13. Display the details of maximum orders above 3000.


SQL> select * from orders where amount>3000;

O_NO O_DATE

AMOUNT

---------- --------- ---------- ---------4 06-MAR-12

4000

6 12-MAR-12

5000

11 26-MAR-12

7000

11

13 05-FEB-12

8000

13

14 07-FEB-12

9000

14

18 09-FEB-12

6000

18

S_NO

14. Display details of orders order number & date wise


select * from orders order by o_date,o_no;

O_NO O_DATE

AMOUNT

S_NO

CBALL

---------- --------- ---------- ---------- ---------13 05-FEB-12

8000

13

14 07-FEB-12

9000

14

18 09-FEB-12

6000

18

1 02-MAR-12

1000

15 02-MAR-12

800

15

2 03-MAR-12

2000

3 05-MAR-12

200

4 06-MAR-12

4000

5 10-MAR-12

300

6 12-MAR-12

5000

7 21-MAR-12

500

15. Display customer's highest ratings in each city.


SQL> select city_name from customer1 where rating= (select MAX(rating) from cust
omer1);

CITY_NAME
-------------------Pathardy

16. Write a query that totals the orders for each day & places the results in
descending order.
select o_date,sum(amount)
2 from orders
3 group by o_date
4 order by o_date desc;

O_DATE

SUM(AMOUNT)

--------- ----------04-JUN-12

2000

25-MAY-12

400

08-MAY-12

600

05-APR-12

900

28-MAR-12

700

26-MAR-12

7000

24-MAR-12

600

23-MAR-12

100

22-MAR-12

400

21-MAR-12

500

12-MAR-12

5000

EXERCIZE 4
1. Add a column curr_bal in orders table for current balance
SQL> select SUM(o_no) from orders;
SUM(O_NO)
---------210
SQL> ALTER TABLE orders ADD(cball number(30))
Table altered.
SQL> select * from orders;
O_NO O_DATE

AMOUNT

S_NO

---------- --------- ---------- ---------- ---------1 02-MAR-12

1000

2 03-MAR-12

2000

3 05-MAR-12

200

4 06-MAR-12

4000

5 10-MAR-12

300

6 12-MAR-12

5000

7 21-MAR-12

500

8 22-MAR-12

400

9 23-MAR-12

100

10 24-MAR-12

600

10

11 26-MAR-12

7000

11

CBALL

2 ) Increase commission of all sales persons by 200.


ows selected.
SQL> UPDATE salespeople SET commission=commission+200;

SQL> select * from salespeople;


S_NO S_NAME

CITY_NAME

COMMISSION

---------- -------------------- -------------------- ---------1 akshay

indapur

300

2 akshta

indapur

400

3 amol

pune

4 aanand
5 vijay
6 reshma
7 rekha
8 ashwini

thane
nashik
indapur

500
600
700
800

indapur

900

aajoti

1000

Exercize 5
1. Display names of all customers matched with the salespeople serving
them.
SQL> select salespeople.s_name,customer1.c_name from salespeople,customer1,cso w
here salespeople.s_no=cso.s_no and customer1.c_no=cso.c_no;

S_NAME

C_NAME

-------------------- -------------------akshay

sonali

akshta

sreya

amol

allen

aanand
vijay
reshma
rekha

josef
soham
sayali
priya

ashwini

jiya

priyanka

sushma

sushma

sagar

sujata

bankat

2. Find all orders by customers not located in same cities as their


Salespersons.
SQL> select orders.o_no,customer1.c_name,salespeople.s_no,salespeople.city_name
from orders,customer1,salespeople,cso where orders.o_no=cso.o_no and customer1.c
_no=cso.c_no and salespeople.s_no=cso.s_no and salespeople.city_name != 'pune';

O_NO C_NAME

S_NO CITY_NAME

---------- -------------------- ---------- -------------------1 sonali

1 indapur

2 sreya

2 indapur

4 josef

4 thane

5 soham

5 nashik

6 sayali

6 indapur

7 priya

7 indapur

8 jiya
9 sushma
10 sagar

8 aajoti
9 baramati
10 akluj

11 bankat

11 akole

12 sujata

12 indapur

3. Display each order number followed by the name of customer who


made it.
SQL> select orders.o_no,customer1.c_name from orders,customer1,cso where orders.
o_no=cso.o_no and customer1.c_no=cso.c_no;

O_NO C_NAME
---------- -------------------1 sonali
2 sreya
3 allen
4 josef
5 soham
6 sayali
7 priya
8 jiya
9 sushma
10 sagar
11 bankat

4. Calculate the amount of salespersons commissions on each order by a


customer with a rating above 100.
SQL> select (salespeople.commission*orders.amount),customer1.c_name from salespe
ople,orders,customer1,cso where salespeople.s_no=cso.s_no and orders.o_no=cso.o_
no and customer1.c_no=cso.c_no and commission>80;

(SALESPEOPLE.COMMISSION*ORDERS.AMOUNT) C_NAME
-------------------------------------- -------------------100000 sonali
400000 sreya
60000 allen
1600000 josef
150000 soham
3000000 sayali
350000 priya
320000 jiya
90000 sushma
600000 sagar
14000000 bankat

(SALESPEOPLE.COMMISSION*ORDERS.AMOUNT) C_NAME
--------------------------------------

--------------------

2100000 sujata
32000000 sudha
45000000 sadhna
4800000 megha
6300000 chetna
16000000 reshma

54000000 ashwini
6000000 rutuja
4400000 vijay

5. Display the pairs of salespeople who are living in the same city. Exclude
combinations of sales people with themselves as well as duplicate rows with the
order reversed.

SQL> select s_name from salespeople where city_name='pune';


S_NAME
-------------------amol

6. Display the names & cities of all customers with same rating as
Hoffman
SQL> select c_name,city_name from customer1 where rating=40;
C_NAME

CITY_NAME

-------------------- -------------------josef

thane

jiya

nashik

rutuja

latur

EXERCISE 6
1. Write a query that uses a sub-query to obtain all orders for the customer named 'Gopal'.
Assume you do not know the customer number.
SQL> select orders.o_no,customer1.c_name from orders,customer1,cso where orders.
o_no=cso.o_no and customer1.c_no=cso.c_no and c_name= 'sujata';
O_NO C_NAME
---------- -------------------12 sujata

2. Write a query that produces the names & ratings of all customers who have aboveaverage orders.

SQL> select c_name, rating from customer1 where rating> (select AVG (rating) from
customer1);

C_NAME

RATING

-------------------- ---------sayali

50

reshma

50

sushma

60

vijay

60

sagar

70

ashwini

70

bankat

80

megha

90

chetna

100

3). Write a query that selects the total amt in orders for each salesperson for whom this total is
greater than the amount of the largest order in table

SQL> select s_no,sum(amount) from orders group by s_no having sum(amount)>(selec


t max(amount)from orders);
no rows selected

EXERCISE 7
3. Write a command that produces the name & number of each salesperson & each
customer with more than one current order. Put results in alphabetical order.
o.s_no and custome
r1.c_no=cso.c_no and orders.o_no=cso.o_no;

S_NO S_NAME

C_NAME

O_DATE

---------- -------------------- -------------------- --------1 akshay

sonali

02-MAR-12

2 akshta

sreya

03-MAR-12

3 amol

allen

05-MAR-12

4 aanand
5 vijay
6 reshma
7 rekha

josef

06-MAR-12

soham

10-MAR-12

sayali

12-MAR-12

priya

21-MAR-12

8 ashwini

jiya

22-MAR-12

9 priyanka

sushma

10 sushma

sagar

11 sujata

bankat

23-MAR-12
24-MAR-12
26-MAR-12

S_NO S_NAME

C_NAME

O_DATE

---------- -------------------- -------------------- --------12 vinod

sujata

28-MAR-12

13 santosh

sudha

05-FEB-12

14 mahesh

sadhna

07-FEB-12

15 allen

megha

02-MAR-12

16 rutuja

chetna

05-APR-12

17 suyog

reshma

04-JUN-12

18 sunita

ashwini

09-FEB-12

19 suraj

rutuja

08-MAY-12

20 rahul

vijay

25-MAY-12

EXERCISE 8
1. Create an index that would permit each salesperson to retrieve
SQL> create INDEX salespeopleINDEX ON salespeople(s_name);
Index created.
2. Create a view that shows all of the customers who have highest ratings.
SQL> create VIEW view_customer AS select c_name,city_name,rating from customer1
where rating>90;
View created.

SQL> select c_name,city_name,rating from view_customer;

C_NAME

CITY_NAME

RATING

-------------------- -------------------- ---------chetna

pathardy

100

3. Create a view that shows number of salespeople in each city

SQL> create VIEW view_sapespeople AS select s_name,city_name,commission from sal


espeople where commission>1000;
View created.

SQL> select s_name,city_name,commission from view_sapespeople;

S_NAME

CITY_NAME

COMMISSION

-------------------- -------------------- ---------sujata

akole

2000

vinod

indapur

3000

santosh

bhigvan

4000

mahesh

barshi

5000

allen

mumbai

6000

rutuja

karmala

7000

suyog

thane

8000

sunita

dound

9000

suraj

pimpry

10000

rahul

tembhurni

11000

Potrebbero piacerti anche