Advertisement
Guest User

Untitled

a guest
Nov 7th, 2016
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.77 KB | None | 0 0
  1. create table Country(
  2. country_ID integer not null,
  3. country_name varchar(255),
  4. country_iso varchar(3) unique,
  5. primary key (country_ID));
  6.  
  7. insert into country(country_id, country_name, country_iso)
  8. values (1, 'საქართველო', 'GEO'),
  9. (2, 'გერმანია', 'DEU'),
  10. (3, 'საფრანგეთი', 'FRA'),
  11. (4, 'ჩეხეთი', 'CZE'),
  12. (5, 'იტალია', 'ITA');
  13.  
  14.  
  15. create table City(
  16. city_ID integer not null,
  17. country_ID integer,
  18. city_name varchar(255),
  19. city_phone_code varchar(30),
  20. primary key (city_ID),
  21. FOREIGN KEY (country_ID) REFERENCES Country(country_ID));
  22.  
  23. insert into city(city_id, country_id, city_name, city_phone_code)
  24. values (1, 1, 'თბილისი', '+995 32'),
  25. (2, 1, 'ქუთაისი', '+995 331'),
  26. (3, 1, 'ბათუმი', '+995 222'),
  27. (4, 2, 'ბერლინი', '+49 30'),
  28. (5, 2, 'მიუნხენი', '+49 89'),
  29. (6, 3, 'პარიზი', '+33 1'),
  30. (7, 3, 'მარსელი', '+33 4'),
  31. (8, 3, 'ლიონი', '+33 4'),
  32. (9, 4, 'პრაღა', '+420'),
  33. (10, 5, 'რომი', '+39 6'),
  34. (11, 5, 'ვენეცია', '+39 41'),
  35. (12, 5, 'ფლორენცია', '+39 55');
  36.  
  37. create table Hotels(
  38. hotel_ID integer not null,
  39. city_ID integer,
  40. hotel_name varchar(255),
  41. Adreess varchar(255),
  42. stars varchar(255),
  43. primary key (hotel_ID),
  44. foreign key (city_ID) REFERENCES city(city_ID)
  45. );
  46.  
  47.  
  48. insert into hotels(hotel_id, city_id, hotel_name, Adreess, stars)
  49. values (1, 1, 'სასტუმრო კოპალა' , 'ძველი თბილისი ჩეხოვის #8', '4 ვარსკვლავიანი'),
  50. (2, 1, 'სასტუმრო მეიდანი', 'ძველი თბილისი გრიშაშვილის #19','3 ვარსკვლავიანი'),
  51. (3, 1, 'სასტუმრო შერატონ მეტეხი პალასი', 'თელავის ქუჩა #20', '5 ვარსკვლავიანი'),
  52. (4, 2, 'საოჯახო სასტუმრო გარდენ ჰაუსი', 'თამარ მეფის ქუჩა #98', '3 ვარსკვლავიანი'),
  53. (5, 2, 'სასტუმრო მაგნოლია პარადისო', 'დავით და კონსტანტინეს ქუჩა #13', '3 ვარსკვლავიანი'),
  54. (6, 2, 'სასტუმრო ედელვაისი', 'ნინოშვილის ქუჩა #145', '3 ვარსკვლავიანი'),
  55. (7, 3, 'სასტუმრო ორბი რეზიდენსი', 'კობალაძის ქუჩა #2', '3 ვარსკვლავიანი'),
  56. (8, 3, 'სასტუმრო ალექსი', 'მელიქიშვილის ქუჩა #102', '3 ვარსკვლავიანი'),
  57. (9, 3, 'საოჯახო სასტუმრო მწვანე კონცხი', 'ბაღის ქუჩა #1', '2 ვარსკვლავიანი'),
  58. (10, 4, 'სასტუმრო Adlon Kempinski', 'Unter den Linden #77', '4 ვარსკვლავიანი'),
  59. (11, 4, 'სასტუმრო Hilton', 'Mohrenstrasse #30', '4 ვარსკვლავიანი'),
  60. (12, 5, 'სასტუმრო Sofitel Munich Bayerpost', 'Bayerstrasse #12', '4 ვარსკვლავიანი'),
  61. (13, 5, 'სასტუმრო Vier Jahreszeiten Kempinski', 'Maximilianstrasse #17', '5 ვარსკვლავიანი'),
  62. (14, 6, 'სასტუმრო Plaza Athenee', '25 Avenue Montaigne', '5 ვარსკვლავიანი'),
  63. (15, 6, 'სასტუმრო Georgette',' 36 Rue du Grenier Saint-Lazare', '3 ვარსკვლავიანი'),
  64. (16, 6, 'სასტუმრო Maison Souquet', '10 Rue de Bruxelles', '4 ვარსკვლავიანი'),
  65. (17, 7, 'სასტუმრო Villa Monticelli',' 96 Rue du Commandant Rolland', '5 ვარსკვლავიანი'),
  66. (18, 7, 'სასტუმრო Dieu', '1 Place Daviel', '5 ვარსკვლავიანი'),
  67. (19, 8, 'სასტუმრო Lyon Bellecour', '20 Quai Dr Gailleton', '4 ვარსკვლავიანი'),
  68. (20, 8, 'სასტუმრო Cour des Loges', '6 Rue du Boeuf', '4 ვარსკვლავიანი'),
  69. (21, 9, 'სასტუმრო Four Seasons', 'Veleslavinova 1098/2a', '5 ვარსკვლავიანი'),
  70. (22, 9, 'სასტუმრო Corinthia', 'Kongresova 1655/1', '4 ვარსკვლავიანი'),
  71. (23, 9, 'სასტუმრო Maximilian', 'Hastalska 752/14', '5 ვარსკვლავიანი'),
  72. (24, 10, 'სასტუმრო The Fifteen Keys', 'Via Urbana 6/7', '3 ვარსკვლავიანი'),
  73. (25, 10, 'სასტუმრო Artemide', 'Via Nazionale 22', '5 ვარსკვლავიანი'),
  74. (26, 11, 'სასტუმრო Locanda Vivaldi', 'Riva degli Schiavoni 4152/4153', '4 ვარსკვლავიანი'),
  75. (27, 11, 'სასტუმრო Metropole', 'Riva degli Schiavoni 4149', '5 ვარსკვლავიანი'),
  76. (28, 11, 'სასტუმრო Palazzina Grassi', 'Ramo Grassi 3247',' 4 ვარსკვლავიანი'),
  77. (29, 12, 'სასტუმრო Villa Cora', 'Viale Machiavelli 18',' 5 ვარსკვლავიანი'),
  78. (30, 12, 'სასტუმრო Santa Maria Novella', 'Piazza di Santa Maria Novella 1',' 4 ვარსკვლავიანი');
  79.  
  80. create table costumers(
  81. costumer_ID integer not null,
  82. Personal_ID varchar(11),
  83. costumer_firstname varchar(255),
  84. costumer_lastname varchar (255),
  85. costumer_sex varchar (10),
  86. costumer_birthday date,
  87. costumer_phone varchar(100),
  88. costumer_email varchar(255),
  89. primary key (costumer_ID)
  90. );
  91.  
  92. create table booked_hotels(
  93. book_id integer not null,
  94. costumer_id integer not null,
  95. hotel_id integer not null,
  96. from_date date,
  97. till_date date,
  98. primary key (book_id),
  99. foreign key (costumer_id) references costumers(costumer_id),
  100. foreign key (hotel_id) references hotels(hotel_id)
  101. );
  102.  
  103. -- 3
  104. insert into costumers(costumer_id, personal_id, costumer_firstname, costumer_lastname, costumer_sex, costumer_birthday, costumer_phone, costumer_email)
  105. values (1, '12345678901', 'jaba', 'ioseliani', 'male', '1939-9-23', '551906834', 'mxedrioni@mail.ru'),
  106. (2, '12345678902', 'juba', 'darsia', 'male', '1944-3-23', '551906844', 'j.dars@mail.ru'),
  107. (3, '12345678903', 'jaba', 'bojgua', 'male', '1964-2-23', '551906824', 'mx.xed@mail.ru'),
  108. (4, '12345678904', 'jimi', 'hendrixi', 'male', '1936-3-21', '551906834', 'rioni@mail.ru'),
  109. (5, '12345678905', 'jimbo', 'nolani', 'male', '1969-7-24', '551986034', 'iori@mail.ru'),
  110. (6, '12345678906', 'goga', 'chachia', 'male', '1999-11-27', '551606834', 'g.cggi@mail.ru'),
  111. (7, '12345678907', 'gia', 'trapaidze', 'male', '1944-4-13', '551906539', 'g.trap@mail.ru'),
  112. (8, '12345678908', 'gaga', 'gvencadze', 'male', '1929-7-4', '551906433', 'dioni@mail.ru'),
  113. (9, '12345678909', 'shura', 'pachulia', 'male', '1999-2-5', '551936834', 'lazika@mail.ru'),
  114. (10, '12345678910', 'gio', 'tabidze', 'male', '1936-11-11', '551916834', 'galaktioni@mail.ru'),
  115. (11, '12345678911', 'zaza', 'chachava', 'male', '1949-8-23', '555206834', 'chachav@mail.ru');
  116.  
  117. -- 4
  118. insert into booked_hotels(book_id, costumer_id, hotel_id, from_date, till_date)
  119. values (1, 1, 1, '2003-3-23', '1944-3-25'),
  120. (2, 2, 1, '2003-6-25', '2004-3-25'),
  121. (3, 2, 12, '2003-7-23', '2004-3-27'),
  122. (4, 2, 2, '2003-4-23', '2004-1-22'),
  123. (5, 2, 2, '2003-1-23', '2004-3-23'),
  124. (6, 2, 3, '2003-8-6', '2004-12-23'),
  125. (7, 2, 3, '2003-11-23', '2004-11-11'),
  126. (8, 2, 3, '2005-4-22', '2005-12-23'),
  127. (9, 3, 11, '2005-3-21', '2006-3-23'),
  128. (10, 7, 10, '2006-3-4', '2007-3-23'),
  129. (11, 3, 4, '2010-3-11', '2010-3-23'),
  130. (12, 4, 3, '2010-4-12', '2011-4-26'),
  131. (13, 5, 13, '2010-3-1', '2011-3-28'),
  132. (14, 6, 6, '2010-7-5', '2011-1-4'),
  133. (15, 7, 7, '2010-12-31', '2011-4-6'),
  134. (16, 8, 1, '2010-4-21', '2011-2-13'),
  135. (17, 9, 23, '2010-1-1', '2011-11-15'),
  136. (18, 10, 3, '2010-11-5', '2011-7-11'),
  137. (19, 11, 5, '2010-5-11', '2012-1-18'),
  138. (20, 4, 28, '2010-3-22', '2011-8-29'),
  139. (21, 7, 19, '2010-3-14', '2011-12-28'),
  140. (22, 7, 19, '2010-4-11', '2011-1-28'),
  141. (23, 7, 19, '2010-3-21', '2011-12-21'),
  142. (24, 7, 19, '2010-6-1', '2011-4-4'),
  143. (25, 7, 19, '2010-7-10', '2011-12-27');
  144.  
  145. -- 5
  146. select c.country_name, c.country_iso, ct.city_name, ct.city_phone_code, h.hotel_name, h.Adreess
  147. from country c
  148. join city ct on (c.country_id = ct.country_id)
  149. join hotels h on (ct.city_ID = h.city_ID)
  150. order by c.country_name;
  151.  
  152. -- 6
  153. select c.country_name, c.country_iso, ct.city_name, ct.city_phone_code, h.hotel_name, h.Adreess, count(b.book_id) booked_number
  154. from country c
  155. join city ct on (c.country_id = ct.country_id)
  156. join hotels h on (ct.city_ID = h.city_ID)
  157. join booked_hotels b on (b.hotel_id = h.hotel_id)
  158. group by c.country_name, c.country_iso, ct.city_name, ct.city_phone_code, h.hotel_name, h.Adreess;
  159.  
  160.  
  161. -- 7
  162. select c.country_name, ct.city_name, h.hotel_name, count(b.book_id) booked_number
  163. from country c
  164. join city ct on (c.country_id = ct.country_id)
  165. join hotels h on (ct.city_ID = h.city_ID)
  166. join booked_hotels b on (b.hotel_id = h.hotel_id)
  167. group by c.country_name, ct.city_name, h.hotel_name
  168. having count(b.book_id) = (select count(book_id) d from booked_hotels group by hotel_id order by d desc limit 1);
  169.  
  170.  
  171. -- 8
  172. select c.personal_id, concat(c.costumer_firstname,' ',c.costumer_lastname), c.costumer_birthday, count(bh.book_id)
  173. from costumers c
  174. join booked_hotels bh on (c.costumer_id = bh.costumer_id)
  175. group by c.personal_id, concat(c.costumer_firstname,' ',c.costumer_lastname), c.costumer_birthday
  176. having count(bh.book_id) = (select count(book_id) d from booked_hotels group by costumer_id order by d desc limit 1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement