1.
Get the name of movie which has run the longest in the multiplex so far.
select movie_name from movie where movie_id
in(select movie_id from current1 where (date_of_closure - date_of_arrival) in
(select max(date_of_closure-date_of_arrival) from current1));
Output:
MOVIE_NAME
---------------------
Terminator-3
2.
Get the average duration of a movie on screen number 'S4'.
Select
avg(to_number(date_of_closure-date_of_arrival)) from current1 where
screen_id='S4';
3)
Create the table DIST_ITEM with the fields (DNO, ITEMNO, QTY):
create
table DIST_ITEM
(dno varchar2(3) references DISTRIBUTOR,
itemno varchar2(3) references ITEM1,
qty number(4));
Insert
the records into the table DIST_ITEM:
Insert
into dist_item values ('&dno','&itemno',&qty);
4) View all the records of table DIST_ITEM
Select
* from dist_item;
Output:
DNO ITEMNO
QTY
-------- -------------- -----
D01 I02 130
D02 I01 500
D03 I05 420
D04 I03 320
D05 I06 160
D02 I04 190
D01 I07
462
D05 I01 256
D03 I04 315
Queries:
1. Add column CONTACT_PERSON to the
distributor table with the not null constraint.
Alter
table distributor add (contact_person varchar2(15) not null);
Output:
Table altered.
2. Create a view LONDON_DIST on
DIST_ITEM which contains only those records where distributors are from London.
Make sure that this condition is checked for every DML against this view.
create
view LONDON_DIST as select di.dno, di.itemno, di.qty from dist_item di,
dist_item d where di.dno=d.dno and upper(daddr) like '%LONDON%' with check
option;
Output:
View
created.
3.
Display detail of all those item that have never been supplied.
Select
* from item1 where itemno not in(select itemno
from dist_item)
No
rows selected.
5.
Delete all those items that have been sulpplied only once.
Delete
from item1 where itemno in(select itemno from dist_item group by itemno having
count(*)=1);
Output:
or
Delete
from item1 where itemno in(select itemno from dist_item group by itemno having
count(*)=1);
no
rows selected.
5.
List the names of distributors who have an 'A' and also a 'B' somewhere in
their names.
Select
* from distributor where dname like '%a%' and dname like '%b%';
no
rows selected.
6.
Count the number of items having the same color but not having weight between
20 and 100.
Select
colour, count(*) from item1 where weight not between 20 and 100 group by
colour;
Output:
COLOUR COUNT(*)
--------------
--------------
red 1
7.
Display all those distributors who have supplied more than 1000 parts of the
same type.
Select
* from distributor where dno in (select dno from dist_item group by dno, itemno
having sum(qty)>1000);
no
rows selected.
8.
Display the average weight of items of same colour provided at least one items
have that colour.
Select
colour, avg (weight) from item1 group by colour having count (*)>1;
Outout:
COLOUR AVG(WEIGHT)
------------- --------------------
red 80
9.
Display the position where a distributor name has an 'OH' in its spelling
somewhere after the forth character.
Select
upper (dname)||' has "OH" in its name at position'||
to_char(instr(upper(dname),'OH',4)) from distributor;
10.
Count the number of distributors who have a phone connection and are supplying
item number 'I100'.
Select
count (*) from distributor d, dist_item di where d.dphone is not null and d.dno
= di.dno and di.itemno=‘i100’;
Output:
COUNT(*)
-------------
0
11.
Create a view on the table in such a way that the view contains the distributor
name, item name and the quantity supplied.
Create
view vdnm_inm_qty as select d.dname, i.iname, di.qty from distributor d, item1
i, dist_item di where d.dno=di.dno and i.itemno=di.itemno;
View
created.
12.
List the name, address and phone number of distributors who have the same three
digits in their number as 'Mr. Talkative'.
select
dname, daddr, dphone from distributor where substr(dphone,1,3)in (select
substr(dphone,1,3) from distributor where lower(dname)='hardik');
Output:
13.
List all distributor names who supply either item I01 or I07 and the quantity
supplied is more than 100.
Select
dname from distributor d, dist_item di, item1 i where di.dno=d.dno and i.itemno=di.itemno
and di.qty>100;
14.
Display the data of the top three heaviest ITEMS.
Select
* from item1 where weight>= (select max(weight) from item1 where weight not
in (select max(weight)from item1 where weight not in (select max(weight)from
item1)) and weight <>(select max(weight) from item1));
Output:
ITE
ITEMNAME COLOUR WEIGHT
-----
--------------- ------------- -----------
I02
Bolt white 100
I04
Hammer green 75
I05
Washer red 110
QUESTION:- 6
1) Create the table WORKER with the fields (worker_id, name,
wage_per_hour, specialized_in, manager_id):
create
table worker
(worker_id
varchar2(3) primary key,
name
varchar2(15) not null,
wage_per_Hour
number(3),
specialised_in
varchar2(5),
manager_Id
varchar2(3) primary key,
constraint
ck_wage check(wage_per_Hour >=0));
Insert
the records into the table WORKER:
Insert into worker
values(‘&worker_id’,’&name’,&wage_per_hour,’&specialised_in’,’&manager_id’);
4.
Change the status to 'Complete' for all those jobs, which started in year 2008.
Update
job set status = 'complete ' where job_id in (select job_id from job_assigned
where to_char(starting_date,'yyyy')='2008');
Output:
2
rows updated.
select
* from job;
JOB
TYPE_OF_JOB S
------
-------------------- -
J01 Packing I
J02 Editing A
J03 Molding
B
J04 Accounting I
J05 Printing B
5.
Display job details of all those jobs where at least 25 workers are working.
Select
* from job where job_id in (select job_id from job_assigned group by job_id
having count (*)>=25);
no
rows selected.
6.
Display all those jobs that are already incompleted.
Select
job_id, type_of_job from job where status='I';
Output:
JOB TYPE_OF_JOB
------
---------------------
J01 Packing
J04 Accounting
7.
Find all the jobs, which begin within the next two weeks.
Select
* from job where job_id in (select job_id from job_assigned where starting_date
<= (sysdate+15));
Output:
JOB TYPE_OF_JOB S
------ ------------ -------- -
J01 Packing I
J04 Accounting I
J05 Printing
B
8.
List all workers who have their wage per hour ten times greater than the wage
of their managers.
Select
name from worker w, job j, job_assigned a where w.worker_id=a. worker_id and
j.job_id =a.job_id and j.type_of_job='Polishing';
no
rows selected
9.
List the names of workers who have been assigned the job of Packing.
Select
w.name from worker w where w.worker_id in (select worker_id from job_assigned
where job_id in (select job_id from job where type_of_job ='Packing'));
Output:
NAME
---------------
Mr.Cacophonix
Dhaval
10.
What is total number of days allocated for printing on the goods for all the
workers together.
Select
sum(number_of_days) from job_assigned where job_id in(select job_id from job
where type_of_job='Printing');
Output:
SUM(NUMBER_OF_DAYS)
-------------------------------------
10
11.
Which workers receive higher than average wage per hour.
Select
* from worker where wage_per_hour > (select avg(wage_per_hour) from worker);
13.
Which workers having specialization in polishing start their job in September?
Select
a.worker_id, a.name from worker a, job_assigned b where
specialised_in='Polishing' and to_char (starting_date,'mon') ='sep';
Output:
WOR
NAME
-------
---------------
W01
Mr.Cacophonix
W02
Dhaval
14.
Display details of workers who are specialized in the same field as that of
Mr.Cacophonix or have a wage per hour more than any of the workers.
Select
* from worker where specialised_in in (select specialised_in from worker where name= ‘Mr.Cacophonix’) or wage_per_hour>
(select max (wage_per_hour) from worker);
(5)
Create the table ISSUE with the fields (issue_id, member_id, book_id,
issue_ret, issue_ret_dt):
create
table issue
(issue_id
varchar2 (3) primary key,
member_id varchar2(3) references member,
book_id varchar2(3) references book_master,
issue_ret varchar2(1),
issue_ret_dt date);
Insert
the records into the table ISSUE:
Insert
into issue values(‘&issue_id’, ’&member_id’, ’&book_id’,
'&issue_ret', '&issue_ret_dt');
View
all the records of the table ISSUE:
Select
* from issue;
Output:
ISS
MEM BOO I ISSUE_RET
-----
------- ------- - -----------------
IS1
M01 B01 A 25-JUL-08
IS2
M05 B03 C 23-APR-08
IS3
M04 B01 A 22-AUG-05
IS4
M02 B03 C 12-JUN-08
IS5
M03 B04 I 27-JUN-08
Queries:
1.
Change the table design of ISSUE table to add a constraint, which will allow
only 'I' or 'R' to be entered in the ISSUE_RET column, which stores the action
whether the book is being issued or returned.
Alter
table issue add constraint constraint_issue_ret check (issue_ret like 'I' or
issu_ret like 'R');
2.
Add a column to the MEMBER table, which will allow us to store the address of
the member.
5.
Display the books that have been issued at the most three times in the year
2003.
Select
* from book_master where book_id in (select book_id from issue where (to_char
(issue_ret_dt,'YYYY')) ='2003' group by book_id having count (*) <=3);
no
rows selected
6.
Display which books of publisher PHI that are issued right now.
Select
bname from book_master b, publisher p, Issue i where b.publ_id=p.publ_id and
p.publ_name like 'PHP’ and b.book_id=i.book_id and i.issue_ret like '1');
no
rows selected
7.
Display details about books whose all copies are issued.
Select
* from book_master where (book_id, total_copies) in (select book_id, count
(issue_ret) from issue where issue_ret like '1' group by book_id);
no
rows selected
8.
Display the book details and members for books, which have been issued between
1st Oct 2005 and 15th Nov 2005.
Select
bname, isbn_no, total_copies, mname, mem_ship_dt from book_master b, member m,
issue i where (issue_ret like 'I') and (issue_ret_dt between '1-oct-2005' and
'15-Nov-2005') and b.book_id=i.book_id and m.member_id=i.member_id;
no
rows selected
9.
Display all staff members who have issued at least two books.
Select
mname, count (i.issu_ret) as "Total Issued Books" from member m,
issue i where (i.member_id=m.member_id and i.issue_ret like 'I') group by mname
having (count(i.issu_ret))>1;
Output:
10. Display details about those
publishers whose more than 100 books are available in the library.
Select
publ_name, count (b.book_id) as "No. of Books" from publisher p,
book_master b where (p.publ_id=b.publ_id) group by publ_name having
(count(b.book_id))>1;
Output:
PUBL_NAME No. of Books
-------------------------
------------------
PHP 3
11.
Delete all those members whose membership has expired.
Delete
from member m, category c where ((sysdate - mem_ship_dt)/365) > c.duration
and m.cat_id=c.cat_id;
Output:
12.
How many members registered in the last three months?
Select
count(*) as "Members Registered in Last Three Months" from member
where mem_ship_dt>(sysdate -90);
Output:
13.
Display since how many months has each staff member registered.
Select
mname, (round ((sysdate - mem_ship_dt) / 30)) as "Months Since Each Member
Registered" from member;
We offer Web Development, Website Designing, Web Hosting, Domain Registration, Graphics Designing, Logo Designing, E-Commerce Development, Open Source Development ....