Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. drop database if exists dbmobil;
  2. create database dbmobil;
  3. use dbmobil;
  4.  
  5. create table tblmobil(
  6. noplat varchar(8) PRIMARY KEY,
  7. mobil varchar(30),
  8. tarifperjam double
  9. );
  10.  
  11. create table tblpenyewa(
  12. noid int PRIMARY KEY,
  13. nama varchar(20),
  14. alamat varchar(30)
  15. );
  16.  
  17. create table tblsewa(
  18. noplat varchar(8),
  19. FOREIGN KEY (noplat) REFERENCES tblmobil(noplat),
  20. noid int,
  21. FOREIGN KEY (noid) REFERENCES tblpenyewa(noid),
  22. jamsewa int,
  23. biayaperjam double
  24. );
  25.  
  26. INSERT INTO tblmobil VALUES
  27. ('H 9234 A','Avanza','25000'),
  28. ('H 9235 A' , 'Xenia' , '25000' ),
  29. ('H 9237 A ', 'Ertiga ', '30000 '),
  30. ('H 9434 A ', 'Panther' ,' 35000') ,
  31. ('H 9534 A ', 'Livina ', '30000 '),
  32. ('H 9634 A ', 'Innova ', '35000 '),
  33. ('H 9734 A ', 'Terios ', '27500 ');
  34.  
  35. INSERT INTO tblpenyewa VALUES
  36. (1, 'Denny' ,' Jl Mataram 32 '),
  37. ( 2, 'Linda' ,' Jl Soedirman 02 '),
  38. ( 3, 'Petra' ,' Jl A Yani 99 '),
  39. ( 4, 'Vania' ,' Jl Let Jend Soeprapto 153 '),
  40. ( 5, 'Debora',' Jl Katamso 55 '),
  41. ( 6, 'Benny' ,' Jl A Yani 678 '),
  42. ( 7, 'Yanny' ,' Jl Mataram 982 '),
  43. ( 8, 'Ditta' ,' Jl Majapahit 1227 '),
  44. ( 9, 'Anna ','Jl DI Panjaitan 552 '),
  45. ( 10, 'Venda' ,' Jl Hasanudin 97 ');
  46.  
  47. INSERT INTO tblsewa VALUES
  48. ('H 9234 A' , 8 , 7 , '25000'),
  49. ('H 9235 A' , 9 , 6 , '25000'),
  50. ('H 9237 A' , 4 , 3 , '30000'),
  51. ('H 9434 A' , 1 , 5 , '35000'),
  52. ('H 9534 A' , 5 , 8 , '30000'),
  53. ('H 9634 A' , 6 , 5 , '35000'),
  54. ('H 9734 A' , 6 , 6 , '27500'),
  55. ('H 9234 A' , 1 , 10 ,' 25000'),
  56. ('H 9235 A' , 4 , 3 , '25000'),
  57. ('H 9237 A' , 2 , 2 , '30000'),
  58. ('H 9434 A' , 5 , 5 , '35000'),
  59. ('H 9534 A' , 9 , 1 , '30000'),
  60. ('H 9634 A' , 7 , 1 , '35000'),
  61. ('H 9734 A' , 4 , 8 , '27500'),
  62. ('H 9234 A' , 6 , 9 , '25000'),
  63. ('H 9235 A' , 7 , 7 , '25000'),
  64. ('H 9237 A' , 4 , 8 , '30000'),
  65. ('H 9434 A' , 7 , 4 , '35000'),
  66. ('H 9534 A' , 7 , 2 , '30000'),
  67. ('H 9634 A' , 9 , 9 , '35000'),
  68. ('H 9734 A' , 7 , 2 , '27500' );
  69.  
  70. -- NOMOR 1
  71. SELECT * FROM tblmobil;
  72. SELECT * FROM tblpenyewa;
  73. SELECT * FROM tblsewa;
  74.  
  75. -- NOMOR 2
  76. SELECT concat(tblmobil.mobil,' [',tblmobil.noplat,']') as Mobil, concat(tblpenyewa.nama,' [',tblpenyewa.alamat,']') as Penyewa
  77. FROM tblmobil,tblpenyewa,tblsewa
  78. WHERE tblmobil.noplat=tblsewa.noplat and tblpenyewa.noid=tblsewa.noid;
  79.  
  80. -- NOMOR 3
  81. SELECT concat(tblmobil.mobil,' [',tblmobil.noplat,']') as Mobil, concat(tblpenyewa.nama,' [',tblpenyewa.alamat,']') as Penyewa
  82. FROM tblmobil,tblpenyewa,tblsewa
  83. WHERE tblmobil.noplat=tblsewa.noplat and tblpenyewa.noid=tblsewa.noid
  84. AND (tblmobil.mobil='Avanza' or tblmobil.mobil='Xenia');
  85.  
  86. -- NOMOR 4
  87. SELECT concat(tblmobil.mobil,' [',tblmobil.noplat,']') as Mobil, concat(tblpenyewa.nama,' [',tblpenyewa.alamat,']') as Penyewa
  88. FROM tblmobil,tblpenyewa,tblsewa
  89. WHERE tblmobil.noplat=tblsewa.noplat and tblpenyewa.noid=tblsewa.noid
  90. AND (tblmobil.mobil not like '%Terios%' and tblmobil.mobil not like '%Innova%');
  91.  
  92. -- NOMOR 5
  93. SELECT concat(tblpenyewa.nama,' [',tblpenyewa.alamat,']') as Penyewa,concat(tblmobil.mobil,' [',tblmobil.noplat,']') as Mobil,tblsewa.jamsewa as Jam
  94. FROM tblmobil,tblpenyewa,tblsewa
  95. WHERE tblmobil.noplat=tblsewa.noplat and tblpenyewa.noid=tblsewa.noid
  96. AND(tblsewa.jamsewa>5);
  97.  
  98. -- NOMOR 6
  99. SELECT concat(tblpenyewa.nama,' [',tblpenyewa.alamat,']') as Penyewa,count(tblpenyewa.nama) as JumlahPenyewa
  100. FROM tblmobil,tblpenyewa,tblsewa
  101. WHERE tblmobil.noplat=tblsewa.noplat and tblpenyewa.noid=tblsewa.noid
  102. AND (tblpenyewa.nama='Vania');
  103.  
  104. -- NOMOR 7
  105. SELECT concat(tblpenyewa.nama,' [',tblpenyewa.alamat,']') as Penyewa,count(tblpenyewa.nama) as JumlahPenyewa,
  106. SUM(tblsewa.jamsewa*tblsewa.biayaperjam) as totalbayar
  107. FROM tblmobil,tblpenyewa,tblsewa
  108. WHERE tblmobil.noplat=tblsewa.noplat and tblpenyewa.noid=tblsewa.noid
  109. AND (tblpenyewa.nama='Debora');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement