Вы находитесь на странице: 1из 4

CREATION OF TABLES :

1. create table production(pc_name varchar2(15) primary key, pc_address varchar2


(15));
2. create table movie(m_title varchar2(15) primary key, m_length number(3), m_yo
r number(4),m_genres varchar2(10),outline varchar2(15),m_pcname references produ
ction on delete cascade);
3. create table actors(a_id number(5) primary key, a_name varchar2(15),a_dob dat
e);
4. create table directors(d_id number(5) primary key, d_name varchar2(15),d_dob
date);
5. create table moviedirectors(md_title references movie, md_id references direc
tors, primary key(md_title,md_id));
6. create table movieactors(ma_title references movie, ma_id references actors,r
ole varchar2(15), primary key(ma_title,ma_id));

TABLE VALUES:
SQL> select * from movie;
M_TITLE M_LENGTH M_GENRES

OUTLINE

M_PCNAME

M_YOR

--------------- ---------- ---------- --------------- --------------- ---------oye

150 action

happy

surya_movies

1998

balu

120 love

abcdefg

a_productions

2000

evildead 90 horror

near to fear

abc_productions

2012

anakonda 60 horror

dare to see

b_productions

2012

surya_movies

2011

nippu

150 action

happy

90 comedy

danger
funny

6 rows selected.
SQL> select * from production;
PC_NAME
--------------surya_movies
abc_productions
a_productions
b_productions

PC_ADDRESS
--------------chennai
chennai
bangalore
bangalore

SQL> select * from actors;


A_ID
---------1
2

A_NAME
--------------naresh
nitin

A_DOB
--------01-JAN-80
01-JUL-86

surya_movies

1999

3 neha
4 nikitha

11-SEP-87
10-JAN-92

SQL> select * from directors;


D_ID
---------11
22
33

D_NAME
--------------shankar
svk
rm

D_DOB
--------01-JAN-80
13-MAR-83
27-JUL-86

SQL> select * from movieactors;


MA_TITLE
MA_ID ROLE
--------------- ---------- --------------balu
1 hero
balu
2 vilan
oye
2 hero
oye
1 vilan
nippu
1 hero
nippu
3 vilan
happy
4 heroin
7 rows selected.
SQL> select * from moviedirectors;
MD_TITLE
MD_ID
--------------- ---------anakonda
11
anakonda
22
anakonda
33
balu
22
evildead
33
nippu
11
oye
11
7 rows selected.
1 QUERY >
select * from movie where m_yor='2012'and m_genres='horror' and m_title in
(select md_title from moviedirectors group by md_title having count(*)>2);
OUTPUT :
M_TITLE M_LENGTH M_GENRES

OUTLINE

M_PCNAME

M_YOR

--------------- ---------- ---------- --------------- --------------anakonda 60 horror

dare to see

b_productions

2012

2. QUERY>
select * from actors where a_id in(select ma_id from movieactors group by ma_ti
tle) in( select m_title from movie where (m_yor NOT BETWEEN 2000 and 2010)) grou
p by m_title having count(*)>1);
PENDING----------------------------------------------

SQL> select * from actors where a_id in(select ma_id from movieactors where ma_t
itle in(select m_title from movie where (m_yor < 2000 or m_yor > 2010) group by
m_title having count(m_title)>1));
no rows selected
SQL> select * from actors where a_id in(select ma_id from movieactors where ma_t
itle in(select m_title from movie where (m_yor not between 2000 and 2010) group
by m_title having count(m_title)>1));
no rows selected
3. QUERY
SQL> select * from production, (select m_pcname from movie group by m_pcname ord
er by count(m_pcname) desc) temp where temp.m_pcname = production.pc_name and r
ownum=1;
PC_NAME
PC_ADDRESS
M_PCNAME
--------------- --------------- --------------surya_movies
chennai
surya_movies
********************************************************************************
alternative query:
SQL> select* from(select m_pcname,count(m_pcname) as no_of_movies from movie gro
up by m_pcname order by no_of_movies desc) where rownum=1;
M_PCNAME
NO_OF_MOVIES
--------------- -----------surya_movies
2
*************************************************************
4.QUERY
SQL> select * from movie where m_title in (select md_title from moviedirectors w
here md_id in ( select d.d_id from directors d, actors a where a.a_dob=d.d_dob))
;
M_TITLE

M_LENGTH M_GENRES

OUTLINE

M_PCNAME

M_YOR

--------------- ---------- ---------- --------------- --------------- ---------oye

150 action

anakonda 60 horror
nippu

150 action

happy
dare to see
danger

surya_movies
b_productions
surya_movies

1998
2012
2011

5. QUERY :
SQL> select * from directors where d_id in(select md_id from moviedirectors wher
e md_title in (select m_title from movie where m_pcname='surya_movies'));
D_ID D_NAME
D_DOB
---------- --------------- --------11 shankar
01-JAN-80
SQL> select * from directors where d_id in(select md_id from moviedirectors wher

e md_title in (select m_title from movie where m_pcname='b_productions'));


D_ID
---------11
22
33

D_NAME
--------------shankar
svk
rm

D_DOB
--------01-JAN-80
13-MAR-83
27-JUL-86

*********************************************************************
SECOND QUERY =-==============================
SQL> select * from actors a, movie m, movieactors ma where a.a_id in(
select ma.ma_id from (
select ma.ma_title from movieactors group by ma.ma_title having count(ma.ma_titl
e) > 1));
and (movie.m_yor not between 2000 and 2010)));
select * from actors, movie m, movieactors ma where a.a_id in(select ma.ma_id f
rom (select ma.ma_title from movieactors group by ma.ma_title having count(ma.ma
_title > 1) and m.m_yor < '2000' or m.m_yor > '2010'

Вам также может понравиться