Practical Query 1 To 17
Practical Query 1 To 17
Sc(CA&IT)
[Create following Three Tables:-
Salesman:
PIYUSH LONDON
1001 12
1002 NIRAJ SURAT 13
SNUM : A Unique number assign to each salesman. SNAME: The name ofsalesman.
CITY :The location ofsalesman.
COMMISSION : The salesman commission on order.
Customer:
customer
CNUM CNAME CITY RATING SNUM
2001 HARDIK LONDON 100 1001
2002 GITA ROME 200 1003
2003 LAXIT SURAT 200 1002
2004 GOVIND BOMBAY 300 1002
2005 CHANDU LONDON 100 1001
2006 CHAMPAK SURAT 300 1007
2007 PRATIK ROME 100 1004
Create table customer
(Cnum number(10)primary key,
Cname varchar2(10),
City varchar2(10),
Rating number(10),
Snum number(10),
Foreign key(snum) references salesman(snum));
Order:-
ONUM : A Unique number assign to each Order. AMOUNT: Amount of order in Rs.
ODATE : The date of order.
CNUM : The number of customer making the order. SNUM : The number of salesman
credited with the sale.
customer table:
Orders table:
Note: Please Do not use ‘order’ as table name. You can use Orders or order1 etc.
Method 2: (If you want add data in all fields then use this method) insert into salesman
values (1001,’PIYUSH’,’LONDON’,12);
insert into salesman values (1002,’NIRAJ’,’SURAT’, 13); insert into salesman values
(1003,’MITI’,’LONDON’,11); insert into salesman values (1004,’RAJESH’,’BARODA’,15);
insert into salesman values (1005,’ANAND’,’NEW DELHI’,10); insert into salesman values
(1006,’RAM’,’PATAN’,10);
insert into salesman values (1007,’LAXMAN’,’BOMBAY’,09);
Method 3: (If you want to add data in selected fields then use this method)
Customer Table:
Method 1:
insert into customer values(&cnum,'&cname','&city',&rating,&snum);
Method 2:
insert into customervalues(2001,’HARDIK’,’LONDON’,100,1001); insert into customer
values(2002,’GITA’,’ROME’,200,1003); insert into customer
values(2003,’LAXIT’,’SURAT’,200,1002); insert into
customervalues(2004,’GOVIND’,’BOMBAY’,300,1002);
insert into customer values(2005,’CHANDU’,’LONDON’,100,1001); insert into customer
values(2006,’CHAMPAK’,’SURAT‘,300,1007); insert into customer
values(2007,’PRATIK’,’ROME’,100,1004);
Method 3:
insert into
customer(cnum,cname,city,rating,snum)values(2001,’HARDIK’,’LONDON’,100,1001);
Orders Table:
Method 1:
insert into orders values(&onum,&amount,'&odate',&cnum,&snum);
Method 2:
insert into orders values(3001,18.69,’10/03/99’,2008,1007); insert into orders
values(3002,767.19,’10/03/99’, 2001,1001); insert into orders
values(3003,1900.10,’10/03/99’,2007,1004); insert into orders
values(3004,5160.45,’10/03/99’,2003,1002); insert into orders
values(3005,1098.25,’10/04/99’,2008,1007); insert into orders
values(3006,1713.12,‘10/04/99’,2002,1003); insert into orders
values(3007,75.75,’10/05/99’,2004,1002); insert into orders
values(3008,4723.00,’10/05/99’,2006,1001); insert into orders
values(3009,1309.95,10/05/99,2004,1002); insert into orders
values(3010,9898.87,10/06/99,2006,1001);
Method 3:
insert into
orders(onum,amount,odate,cnum,snum)values(3001,18.69,’10/03/99’,2008,1007);
ONUM ----------
---------- AMOUNT ---------
ODATE
========================================================
==========
Give all the information about all the customers with salesman number 1001.
SQL> select * from customer where snum=1001; CNUM CNAME CITY RATING
SNUM
---------- ---------- ---------- ---------- ----------
2001 hardik London 100 1001
2005 chandu London 100 1001
========================================================
==========
Display the information in the sequence of city, sname, snum and Commission.
7 rows selected.
========================================================
==========
========================================================
==========
4. List of snum of all salesmen with orders in order table without an duplicates.
SNUM
----------
1001
1002
1003
1004
1007
========================================================
==========
7 rows selected.
========================================================
==========
List out names and cities of all salesmen in London with commission above10%
List all customers excluding those with rating <= 100 or they are located in Rome.
========================================================
==========
List all order for more than Rs.1000 except the orders of snum,1006 of 10/03/99 ONUM
AMOUNTODATE CNUM SNUM
---------- ---------- --------- ---------- ----------
3001 18.6910-MAR-99 2008 1007
300 767.19 10-MAR- 2001 1001
2 99
300 1900.1 10-MAR- 2007 1004
3 99
300 5160.45 10-MAR- 2003 1002
4 99
300 1098.25 10-APR- 2008 1007
5 99
300 1713.12 10-APR- 2002 1003
6 99
300 75.75 10-MAY-99 2004 1002
7
300 4723 10-MAY-99 2006 1001
8
300 1309.95 10-MAY- 2004 1002
9 99
301 9898.87 10-JUN- 2006 1001
0 99
SQL>select * from orders where amount>1000 and not(snum=1006andodate='10-mar-
99'); ONUM AMOUNTODATE CNUM SNUM
---------- ---------- --------- ---------- ---------- 3003 1900.110-MAR-99 2007 1004
300 5160.45 10-MAR- 2003 1002
4 99
List all orders taken on 10th March, April and June 1999.
Or
SQL> select * from customer where cname like 'a%' or cname like 'b%' or cname like 'c%'
or cname like 'd%' or cname like 'e%' or cname like 'f%' or cname like 'g%';
4 rows selected
========================================================
==========
SQL> select * from orders where amount=0 or amount is NULL; no rows selected
========================================================
==========
OR
SQL> select snum, max(amount) from orders where snum in(1002,1007) group by snum;
OR
SQL>select snum,max(amount)max from orders group by snum having snum=1002 or
snum=1007; SNUM MAX
---------- ----------
1002 5160.45
1007 1098.25
OR
SQL> select snum,max(amount) max from orders where snum=1002 or snum=1007 grop
bysnum; SNUM MAX
---------- ---------- 1002 5160.45
1007 1098.25
========================================================
==========
SQL> select sum(amount) as "Total Amount of Orders" from orders; Total Amount of
Orders
----------------------
26665.37
========================================================
==========