Guest User

Untitled

a guest
Nov 28th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.56 KB | None | 0 0
  1. drop database if exists dbKompetisiBasket;
  2. create database dbKompetisiBasket;
  3.  
  4. use dbKompetisiBasket;
  5.  
  6. create table tblTim
  7. (nouruttim int primary key,
  8. namatim varchar(100),
  9. tempatlatihan varchar(100),
  10. alamat varchar(100),
  11. nourutlawan int,
  12. hasil1 int,
  13. hasil2 int,
  14. tanggaltanding timestamp,
  15. foreign key(nourutlawan) references tblTim(nouruttim));
  16.  
  17. insert into tblTim (nouruttim, namatim, tempatlatihan, alamat)
  18. values
  19. (1, 'Singa Putih', 'Samirono','Yogyakarta' ),
  20. (2, 'Macan Terbang', 'Kepuh','Yogyakarta'),
  21. (3, 'Buana Jaya', 'Klitren','Yogyakarta'),
  22. (4, 'Gajah Mungkur', 'Ungaran','Semarang'),
  23. (5, 'Abadi Semesta', 'Dr. Cipto','Semarang'),
  24. (6, 'Patrika Jaya', 'Gondokusumo','Solo'),
  25. (7, 'Pelita Abadi', 'Tanah Abang','Jakarta'),
  26. (8, 'Flobamora Raya', 'Ruteng','Flores');
  27.  
  28. update tblTim set nourutlawan=3, hasil1=103, hasil2=90, tanggaltanding = '2008-10-10' where nouruttim=1;
  29. update tblTim set nourutlawan=5, hasil1=90, hasil2=87, tanggaltanding = '2008-11-11' where nouruttim=2;
  30. update tblTim set nourutlawan=7, hasil1=94, hasil2=98, tanggaltanding = '2008-09-12' where nouruttim=3;
  31. update tblTim set nourutlawan=6, hasil1=83, hasil2=78, tanggaltanding = '2008-06-13' where nouruttim=4;
  32. update tblTim set nourutlawan=8, hasil1=75, hasil2=96, tanggaltanding = '2008-02-14' where nouruttim=5;
  33. update tblTim set nourutlawan=2, hasil1=97, hasil2=87, tanggaltanding = '2008-04-15' where nouruttim=6;
  34. update tblTim set nourutlawan=1, hasil1=82, hasil2=99, tanggaltanding = '2008-05-16' where nouruttim=7;
  35. update tblTim set nourutlawan=4, hasil1=71, hasil2=84, tanggaltanding = '2008-07-17' where nouruttim=8;
  36.  
  37. create table tblAnggota
  38. (nourutanggota int primary key,
  39. nama varchar(100),
  40. alamat varchar(100),
  41. tinggi int,
  42. berat int);
  43.  
  44. insert into tblAnggota values
  45. (1, 'Budi', 'Jl Sudirman 45', 189, 70),
  46. (2, 'Andre', 'Jl Soeharto 35', 177, 70),
  47. (3, 'Jony', 'Jl S Parman 67', 189, 70),
  48. (4, 'Didin', 'Jl A Yani 23', 178, 70),
  49. (5, 'Unang', 'Jl Diponegoro 198', 189, 70),
  50. (6, 'Joko', 'Jl Imam Bonjol 78', 178, 70),
  51. (7, 'Purwoko', 'Jl Mawar 4', 187, 70),
  52. (8, 'Yoyok', 'Jl Melati 26', 185, 70),
  53. (9, 'Edward', 'Jl Flamboyan 190', 189, 70),
  54. (10, 'Ferdi', 'Jl Gajah 14', 170, 70),
  55. (11, 'Filipus', 'Jl Singa 56', 186, 70),
  56. (12, 'George', 'Jl Kamboja 187', 189, 70),
  57. (13, 'Robi', 'Jl Menjangan 190', 189, 70),
  58. (14, 'Franky', 'Jl Jetis 87', 183, 70),
  59. (15, 'Yanto', 'Jl Colombo 47', 181, 70),
  60. (16, 'Jack', 'Jl Gejayan 27', 178, 70),
  61. (17, 'David', 'Jl Kancil 36', 179, 70),
  62. (18, 'Bire', 'Jl Cemara 87', 184, 70),
  63. (19, 'Anton', 'Jl Gerilya 45', 188, 70),
  64. (20, 'Markus', 'Jl Mataram 98', 183, 70),
  65. (21, 'Handi', 'Jl Gajah Mada 35', 184, 70),
  66. (22, 'Hartono', 'Jl Panglima Sudirman 74', 185, 70);
  67.  
  68. update tblAnggota Set berat = tinggi - 105;
  69.  
  70. create table tblRelasi
  71. (nouruttim int,
  72. nourutanggota int,
  73. tanggaldaftar timestamp,
  74. nopunggung int,
  75. foreign key (nouruttim) references tblTim(nouruttim),
  76. foreign key (nourutanggota) references tblAnggota(nourutanggota)
  77. );
  78.  
  79. insert into tblRelasi
  80. values
  81. (1, 1, '2007-10-11',67),
  82. (2, 2, '2007-11-14',45),
  83. (1, 3, '2007-02-23',65),
  84. (1, 4, '2007-06-25',77),
  85. (8, 5, '2007-04-24',87),
  86. (3, 6, '2007-03-27',56),
  87. (1, 7, '2007-05-25',45),
  88. (1, 8, '2007-09-29',34),
  89. (4, 9, '2007-11-21',87),
  90. (1, 10, '2007-02-12',94),
  91. (7, 11, '2007-04-16',25),
  92. (1, 12, '2007-03-18',74),
  93. (5, 13, '2007-05-16',28),
  94. (1, 14, '2007-07-13',39),
  95. (6, 15, '2007-08-10',43),
  96. (1, 15, '2007-11-18',15),
  97. (8, 17, '2007-12-12',23);
  98.  
  99. /*Nomor1*/
  100. select concat(tblTim.namatim," - ",tblTim.alamat) as "Nama Tim Basket - Asal", tblAnggota.nama as "Nama Anggota Tim"
  101. from tblRelasi,tblTim,tblAnggota
  102. where tblTim.nouruttim=tblRelasi.nouruttim and tblAnggota.nourutanggota=tblRelasi.nourutanggota;
  103.  
  104. /*Nomor2*/
  105. select tblAnggota.nama as "Anggota",tblRelasi.tanggaldaftar as "Tanggal Daftar",tblTim.tanggaltanding as "Waktu Tanding",
  106. DATEDIFF(tblTim.tanggaltanding,tblRelasi.tanggaldaftar) as "Selisih Waktu"
  107. from tblRelasi
  108. inner join tblTim on(tblTim.nouruttim=tblRelasi.nouruttim)
  109. inner join tblAnggota on (tblAnggota.nourutanggota=tblRelasi.nourutanggota);
  110.  
  111. /*Nomor3*/
  112. select tblAnggota.nama as "Anggota,Tinggi < 185",tblRelasi.nopunggung as "Nomor Punggung",year(tblRelasi.tanggaldaftar) as "Tahun Daftar"
  113. from tblRelasi
  114. inner join tblTim on(tblTim.nouruttim=tblRelasi.nouruttim)
  115. inner join tblAnggota on (tblAnggota.nourutanggota=tblRelasi.nourutanggota)
  116. where tblAnggota.tinggi < 185
  117. group by tblAnggota.tinggi asc;
  118.  
  119. /*Nomor4 SESUAI SOAL*/
  120. select concat(tblAnggota.nama,",",tblAnggota.alamat) as "Anggota-alamat, berat > 75", tblTim.alamat as "Dari Yogyakarta atau Semarang"
  121. from tblRelasi
  122. inner join tblTim on(tblTim.nouruttim=tblRelasi.nouruttim)
  123. inner join tblAnggota on (tblAnggota.nourutanggota=tblRelasi.nourutanggota)
  124. where tblAnggota.berat > 75 and (tblTim.alamat ="Semarang" or tblTim.alamat="Yogyakarta")
  125. ORDER by tblAnggota.berat asc;
  126.  
  127. /*Nomor 5*/
  128. select tim1.namatim as "Tim",tim2.namatim as "Lawan",tim1.hasil1 as "Hasil Tim",tim1.hasil2 as "Hasil Lawan",
  129. if((tim1.hasil2-tim1.hasil1)<0, (tim1.hasil2-tim1.hasil1)*-1,(tim1.hasil2-tim1.hasil1)) as "Selisih",
  130. if(tim1.hasil2>tim1.hasil1,tim2.namatim,tim1.namatim) as "Yang Menang"
  131. from tblTim as tim1,tblTim as tim2
  132. where tim1.nouruttim=tim2.nourutlawan;
  133.  
  134. /*Nomor6*/
  135. select tblTim.namatim as "Nama Tim", count(tblRelasi.nouruttim) as "Jumlah pemain >1 (urut DESC)"
  136. from tblRelasi
  137. inner join tblTim on(tblTim.nouruttim=tblRelasi.nouruttim)
  138. inner join tblAnggota on (tblAnggota.nourutanggota=tblRelasi.nourutanggota)
  139. group by tblTim.namatim
  140. having count(tblRelasi.nouruttim) > 1
  141. order by count(tblRelasi.nouruttim) desc;
Advertisement
Add Comment
Please, Sign In to add comment