Advertisement
alexarcan

dbd_ex2

Nov 13th, 2016
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.12 KB | None | 0 0
  1.  
  2. DROP TABLE "ASOCIERE" cascade constraints;
  3. DROP TABLE "CONT" cascade constraints;
  4. DROP TABLE "UTILIZATOR" cascade constraints;
  5. --------------------------------------------------------
  6. -- DDL for Table ASOCIERE
  7. --------------------------------------------------------
  8.  
  9. CREATE TABLE "ASOCIERE"
  10. ( "ID_UTIL" VARCHAR2(20 BYTE),
  11. "ID_CONT" VARCHAR2(20 BYTE)
  12. ) ;
  13. --------------------------------------------------------
  14. -- DDL for Table CONT
  15. --------------------------------------------------------
  16.  
  17. CREATE TABLE "CONT"
  18. ( "ID_CONT" VARCHAR2(20 BYTE),
  19. "DURATA" VARCHAR2(20 BYTE),
  20. "CANTATITATE_DATE" NUMBER
  21. ) ;
  22. --------------------------------------------------------
  23. -- DDL for Table UTILIZATOR
  24. --------------------------------------------------------
  25.  
  26. CREATE TABLE "UTILIZATOR"
  27. ( "ID_UTIL" VARCHAR2(20 BYTE),
  28. "NUME" VARCHAR2(30 BYTE)
  29. ) ;
  30. REM INSERTING into ASOCIERE
  31. Insert into ASOCIERE (ID_UTIL,ID_CONT) values ('U01','C01');
  32. Insert into ASOCIERE (ID_UTIL,ID_CONT) values ('U01','C02');
  33. Insert into ASOCIERE (ID_UTIL,ID_CONT) values ('U01','C03');
  34. Insert into ASOCIERE (ID_UTIL,ID_CONT) values ('U02','C04');
  35. Insert into ASOCIERE (ID_UTIL,ID_CONT) values ('U03','C05');
  36. Insert into ASOCIERE (ID_UTIL,ID_CONT) values ('U04','C06');
  37. Insert into ASOCIERE (ID_UTIL,ID_CONT) values ('U05','C07');
  38. Insert into ASOCIERE (ID_UTIL,ID_CONT) values ('U05','C08');
  39. REM INSERTING into CONT
  40. Insert into CONT (ID_CONT,DURATA,CANTATITATE_DATE) values ('C01','3m',100);
  41. Insert into CONT (ID_CONT,DURATA,CANTATITATE_DATE) values ('C02','3m',75);
  42. Insert into CONT (ID_CONT,DURATA,CANTATITATE_DATE) values ('C03','20m',500);
  43. Insert into CONT (ID_CONT,DURATA,CANTATITATE_DATE) values ('C04','1h',1240);
  44. Insert into CONT (ID_CONT,DURATA,CANTATITATE_DATE) values ('C05','40m',840);
  45. Insert into CONT (ID_CONT,DURATA,CANTATITATE_DATE) values ('C06','1m',10);
  46. Insert into CONT (ID_CONT,DURATA,CANTATITATE_DATE) values ('C07','15m',300);
  47. Insert into CONT (ID_CONT,DURATA,CANTATITATE_DATE) values ('C08','25m',400);
  48. REM INSERTING into UTILIZATOR
  49. Insert into UTILIZATOR (ID_UTIL,NUME) values ('U01','Popescu Gheorghe');
  50. Insert into UTILIZATOR (ID_UTIL,NUME) values ('U02','Paran Bianca');
  51. Insert into UTILIZATOR (ID_UTIL,NUME) values ('U03','Adriana Petrisor');
  52. Insert into UTILIZATOR (ID_UTIL,NUME) values ('U04','Sturza Claudiu');
  53. Insert into UTILIZATOR (ID_UTIL,NUME) values ('U05','Petrisor Ioan');
  54. --------------------------------------------------------
  55. -- DDL for Index CONT_PK
  56. --------------------------------------------------------
  57.  
  58. CREATE UNIQUE INDEX "CONT_PK" ON "CONT" ("ID_CONT")
  59. ;
  60. --------------------------------------------------------
  61. -- DDL for Index UTILIZATOR_PK
  62. --------------------------------------------------------
  63.  
  64. CREATE UNIQUE INDEX "UTILIZATOR_PK" ON "UTILIZATOR" ("ID_UTIL")
  65. ;
  66. --------------------------------------------------------
  67. -- Constraints for Table CONT
  68. --------------------------------------------------------
  69.  
  70. ALTER TABLE "CONT" ADD CONSTRAINT "CONT_PK" PRIMARY KEY ("ID_CONT") ENABLE;
  71.  
  72. ALTER TABLE "CONT" MODIFY ("ID_CONT" NOT NULL ENABLE);
  73. --------------------------------------------------------
  74. -- Constraints for Table UTILIZATOR
  75. --------------------------------------------------------
  76.  
  77. ALTER TABLE "UTILIZATOR" MODIFY ("ID_UTIL" NOT NULL ENABLE);
  78.  
  79. ALTER TABLE "UTILIZATOR" ADD CONSTRAINT "UTILIZATOR_PK" PRIMARY KEY ("ID_UTIL") ENABLE;
  80. --------------------------------------------------------
  81. -- Ref Constraints for Table ASOCIERE
  82. --------------------------------------------------------
  83.  
  84. ALTER TABLE "ASOCIERE" ADD CONSTRAINT "CONT_FK" FOREIGN KEY ("ID_CONT")
  85. REFERENCES "CONT" ("ID_CONT") ENABLE;
  86.  
  87. ALTER TABLE "ASOCIERE" ADD CONSTRAINT "UTIL_FK" FOREIGN KEY ("ID_UTIL")
  88. REFERENCES "UTILIZATOR" ("ID_UTIL") ENABLE;
  89.  
  90.  
  91. /*b. Sa se afiseze un top al utilizatorilor in functie de numarul "cantitatea"
  92. totala de date utilizata (pe toate conturile). Se vor afisa
  93. doar utilizatorii care au depasit 100MB (sau alta valoare arbitrara)
  94. */
  95.  
  96.  
  97. select * from (select u.id_util, sum(c.cantatitate_date) as cantitatetotala from utilizator u, cont c, asociere a
  98. where u.id_util=a.id_util and c.id_cont=a.id_cont
  99. group by u.id_util
  100. order by cantitatetotala DESC) where cantitatetotala>500;
  101.  
  102. /*c. Sa se afiseze toti utilizatorii al caror trafic total nu depaseste
  103. media traficului inregistrat in baza de date (trafic total raportat
  104. la numarul de utilizatori)
  105. */
  106.  
  107. /* media traficului integistrat in baza de date este 433.125
  108. U01 - are trafic total 675 Mb
  109. U02 - 1240 Mb
  110. U03 - 840
  111. U04 - 10
  112. U05 - 700
  113. */
  114.  
  115. select * from (select u.id_util, sum(c.cantatitate_date) as Trafictotal from utilizator u, cont c, asociere a
  116. where u.id_util=a.id_util and c.id_cont=a.id_cont
  117. group by u.id_util
  118. order by trafictotal desc) where trafictotal < (select avg(cantatitate_date) from cont c);
  119.  
  120. /* d Sa se elimine din baza de date ultimii trei utilizatori in ordinea
  121. traficului total generat. In acest pas se vor elimina atat conturile
  122. cat si sesiunile acestora
  123. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement