Advertisement
Coolcap5

3rd text

Mar 19th, 2024
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 3.44 KB | None | 0 0
  1. CREATE TABLE ACTOR (
  2. ACT_ID NUMBER (3),
  3. ACT_NAME VARCHAR (20),
  4. ACT_GENDER CHAR (1),
  5. PRIMARY KEY (ACT_ID));
  6.  
  7. CREATE TABLE DIRECTOR (
  8. DIR_ID NUMBER (3),
  9. DIR_NAME VARCHAR (20),
  10. DIR_PHONE NUMBER (10),
  11. PRIMARY KEY (DIR_ID));
  12.  
  13. CREATE TABLE MOVIES (
  14. MOV_ID NUMBER (4),
  15. MOV_TITLE VARCHAR (25),
  16. MOV_YEAR NUMBER (4),
  17. MOV_LANG VARCHAR (12),
  18. DIR_ID NUMBER (3),
  19. PRIMARY KEY (MOV_ID),
  20. FOREIGN KEY (DIR_ID) REFERENCES DIRECTOR (DIR_ID));
  21.  
  22. CREATE TABLE MOVIE_CAST (
  23. ACT_ID NUMBER (3),
  24. MOV_ID NUMBER (4),
  25. ROLE VARCHAR (10),
  26. PRIMARY KEY (ACT_ID, MOV_ID),
  27. FOREIGN KEY (ACT_ID) REFERENCES ACTOR (ACT_ID),
  28. FOREIGN KEY (MOV_ID) REFERENCES MOVIES (MOV_ID));
  29.  
  30. CREATE TABLE RATING (
  31. MOV_ID NUMBER (4),
  32. REV_STARS VARCHAR (25),
  33. PRIMARY KEY (MOV_ID),
  34. FOREIGN KEY (MOV_ID) REFERENCES MOVIES (MOV_ID));
  35.  
  36.  
  37. INSERT INTO ACTOR VALUES (301, 'ANUSHKA', 'F');
  38. INSERT INTO ACTOR VALUES (302, 'PRABHAS', 'M');
  39. INSERT INTO ACTOR VALUES (303, 'PUNITH', 'M');
  40. INSERT INTO ACTOR VALUES (304, 'JERMY', 'M');
  41.  
  42. INSERT INTO DIRECTOR VALUES (60, 'RAJAMOULI', 8751611001);
  43. INSERT INTO DIRECTOR VALUES (61, 'HITCHCOCK', 7766138911);
  44. INSERT INTO DIRECTOR VALUES (62, 'FARAN', 9986776531);
  45.  
  46. INSERT INTO DIRECTOR VALUES (63, 'STEVEN SPIELBERG', 8989776530);
  47. INSERT INTO MOVIES VALUES (1001, 'BAHUBALI-2', 2017, 'TELAGU', 60);
  48. INSERT INTO MOVIES VALUES (1002, 'BAHUBALI-1', 2015, 'TELAGU', 60);
  49. INSERT INTO MOVIES VALUES (1003, 'AKASH', 2008, 'KANNADA', 61);
  50. INSERT INTO MOVIES VALUES (1004, 'WAR HORSE', 2011, 'ENGLISH', 63);
  51.  
  52. INSERT INTO MOVIE_CAST VALUES (301, 1002, 'HEROINE');
  53. INSERT INTO MOVIE_CAST VALUES (301, 1001, 'HEROINE');
  54. INSERT INTO MOVIE_CAST VALUES (303, 1003, 'HERO');
  55. INSERT INTO MOVIE_CAST VALUES (303, 1002, 'GUEST');
  56. INSERT INTO MOVIE_CAST VALUES (304, 1004, 'HERO');
  57.  
  58. INSERT INTO RATING VALUES (1001, 4);
  59. INSERT INTO RATING VALUES (1002, 2);
  60. INSERT INTO RATING VALUES (1003, 5);
  61. INSERT INTO RATING VALUES (1004, 4);
  62.  
  63.  
  64. 1. List the titles OF ALL movies directed BY ‘Hitchcock’.
  65. SELECT MOV_TITLE
  66. FROM MOVIES
  67. WHERE DIR_ID IN (SELECT DIR_ID
  68. FROM DIRECTOR
  69. WHERE DIR_NAME = ‘HITCHCOCK’);
  70.  
  71. 2. Find the movie names WHERE one OR more actors acted IN two OR more movies.
  72. SELECT MOV_TITLE
  73. FROM MOVIES M, MOVIE_CAST MV
  74. WHERE M.MOV_ID=MV.MOV_ID AND ACT_ID IN (SELECT ACT_ID
  75. FROM MOVIE_CAST GROUP BY ACT_ID
  76. HAVING COUNT (ACT_ID)>1)
  77. GROUP BY MOV_TITLE
  78. HAVING COUNT (*)>1;
  79.  
  80. 3. List ALL actors who acted IN a movie before 2000 AND also IN a movie after 2015 (USE
  81. JOIN operation).
  82. SELECT ACT_NAME, MOV_TITLE, MOV_YEAR
  83. FROM ACTOR A
  84. 18CSL58:DBMS Lab Manual 2022-23
  85. RNSIT, Bangalore Page 38
  86. JOIN MOVIE_CAST C
  87. ON A.ACT_ID=C.ACT_ID
  88. JOIN MOVIES M
  89. ON C.MOV_ID=M.MOV_ID
  90. WHERE M.MOV_YEAR NOT BETWEEN 2000 AND 2015;
  91. OR
  92. SELECT A.ACT_NAME, A.ACT_NAME, C.MOV_TITLE, C.MOV_YEAR
  93. FROM ACTOR A, MOVIE_CAST B, MOVIES C
  94. WHERE A.ACT_ID=B.ACT_ID
  95. AND B.MOV_ID=C.MOV_ID
  96. AND C.MOV_YEAR NOT BETWEEN 2000 AND 2015;
  97.  
  98. 4. Find the title OF movies AND NUMBER OF stars FOR each movie that has AT LEAST one
  99. rating AND find the highest NUMBER OF stars that movie received. Sort the result BY
  100. movie title.
  101. SELECT MOV_TITLE, MAX (REV_STARS)
  102. FROM MOVIES
  103. INNER JOIN RATING USING (MOV_ID)
  104. GROUP BY MOV_TITLE
  105. HAVING MAX (REV_STARS)>0
  106. ORDER BY MOV_TITLE;
  107.  
  108. 5. UPDATE rating OF ALL movies directed BY ‘Steven Spielberg’ TO 5
  109. KL
  110. UPDATE RATING
  111. SET REV_STARS=5
  112. WHERE MOV_ID IN (SELECT MOV_ID FROM MOVIES
  113. WHERE DIR_ID IN (SELECT DIR_ID
  114. FROM DIRECTOR
  115. WHERE DIR_NAME = ‘STEVEN
  116. SPIELBERG’));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement