querys.sql 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. SELECT COUNT(1) from hotels;
  2. SELECT COUNT(1) from hst_hotel;
  3. SELECT COUNT(1) from saas_hotel;
  4. SELECT MAX(LENGTH(en_name)),MAX(LENGTH(phone)),MAX(LENGTH(en_address)) from saas_hotel;
  5. SELECT MAX(LENGTH(hotel_name)),MAX(LENGTH(phone)),MAX(LENGTH(address)) from hotels;
  6. SELECT city FROM hotels group by city;
  7. SELECT province FROM hotels group by province;
  8. SELECT * FROM hotels WHERE country<>'China' or city='Hong Kong' or city='Macau' or province='Taiwan' ORDER BY country,province,city;
  9. SELECT * from saas_hotel limit 10;
  10. SELECT * from saas_hotel WHERE country<>'中国' and country<>'其他' limit 10;
  11. SELECT * from hotels WHERE province='Taiwan' limit 10;
  12. SELECT * from hotels WHERE country<>'China' limit 10;
  13. SELECT phone, lon, lat from hotels WHERE hotel_id=118;
  14. UPDATE hotels SET lon=null,lat=null WHERE hotel_id=118;
  15. SELECT * FROM hotels WHERE lon is null;
  16. SELECT hotel_id, COUNT(1) from hotels group by hotel_id HAVING count(1)>1;
  17. INSERT INTO hotels_temp
  18. SELECT h.hotel_id, h.hotel_name, h.link, h.slug, h.country, h.province, h.city, h.district, h.address, h.phone, h.site_url, h.rooms, h.hotel_presentation, h.meeting_facilities,
  19. h.images, h.total_rooms, h.hotel_free_wifi, h.total_meeting_rooms, h.meeting_room_max_sqm, h.meeting_room_max_height, h.projector_resolution, h.total_restaurants,
  20. h.room_quantity, h.meeting_room_quantity, h.meeting_room_facilities, h.restaurant_remark, h.distances, h.brand, h.attachments, h.lon, h.lat,
  21. sh.country as `s_country`, sh.province as `s_province`, sh.city as `s_city`, sh.en_name as `s_name`, sh.en_address as `s_address`, sh.phone as `s_phone`,
  22. sh.hop_id, sh.id as `s_id`, sh.lon as `s_lon`, sh.lat as `s_lat`, sh.loc_type as `s_loc_type`
  23. FROM hotels h
  24. inner join saas_hotel sh on lower(trim(sh.en_name)) = lower(trim(h.hotel_name))
  25. WHERE h.s_id is null and h.hotel_id in
  26. (
  27. SELECT h.hotel_id FROM hotels h
  28. inner join saas_hotel sh on lower(trim(sh.en_name)) = lower(trim(h.hotel_name))
  29. WHERE h.s_id is null AND h.hotel_id not in (11930, 16280, 24797, 24329)
  30. GROUP BY h.hotel_id HAVING COUNT(1)=1
  31. ) ORDER BY h.country, h.province, h.city, h.district
  32. ;
  33. INSERT INTO hotels_temp
  34. SELECT h.hotel_id, h.hotel_name, h.link, h.slug, h.country, h.province, h.city, h.district, h.address, h.phone, h.site_url, h.rooms, h.hotel_presentation, h.meeting_facilities,
  35. h.images, h.total_rooms, h.hotel_free_wifi, h.total_meeting_rooms, h.meeting_room_max_sqm, h.meeting_room_max_height, h.projector_resolution, h.total_restaurants,
  36. h.room_quantity, h.meeting_room_quantity, h.meeting_room_facilities, h.restaurant_remark, h.distances, h.brand, h.attachments, h.lon, h.lat,
  37. sh.country as `s_country`, sh.province as `s_province`, sh.city as `s_city`, sh.en_name as `s_name`, sh.en_address as `s_address`, sh.phone as `s_phone`,
  38. sh.hop_id, sh.id as `s_id`, sh.lon as `s_lon`, sh.lat as `s_lat`, sh.loc_type as `s_loc_type`
  39. FROM hotels h
  40. inner join saas_hotel sh on lower(trim(sh.en_address)) = lower(trim(h.address))
  41. WHERE h.s_id is null and h.hotel_id in
  42. (
  43. SELECT h.hotel_id FROM hotels h
  44. inner join saas_hotel sh on lower(trim(sh.en_address)) = lower(trim(h.address))
  45. WHERE h.s_id is null
  46. GROUP BY h.hotel_id HAVING COUNT(1)=1
  47. ) ORDER BY h.country, h.province, h.city, h.district
  48. ;
  49. INSERT INTO hotels_temp
  50. SELECT h.hotel_id, h.hotel_name, h.link, h.slug, h.country, h.province, h.city, h.district, h.address, h.phone, h.site_url, h.rooms, h.hotel_presentation, h.meeting_facilities,
  51. h.images, h.total_rooms, h.hotel_free_wifi, h.total_meeting_rooms, h.meeting_room_max_sqm, h.meeting_room_max_height, h.projector_resolution, h.total_restaurants,
  52. h.room_quantity, h.meeting_room_quantity, h.meeting_room_facilities, h.restaurant_remark, h.distances, h.brand, h.attachments, h.lon, h.lat,
  53. sh.country as `s_country`, sh.province as `s_province`, sh.city as `s_city`, sh.en_name as `s_name`, sh.en_address as `s_address`, sh.phone as `s_phone`,
  54. sh.hop_id, sh.id as `s_id`, sh.lon as `s_lon`, sh.lat as `s_lat`, sh.loc_type as `s_loc_type`
  55. FROM hotels h
  56. inner join saas_hotel sh on REPLACE(trim(BOTH '+' FROM sh.phone), '-', '') = REPLACE(trim(BOTH '+' FROM h.phone), '-', '')
  57. WHERE h.s_id is null and h.hotel_id in
  58. (
  59. SELECT h.hotel_id FROM hotels h
  60. inner join saas_hotel sh on REPLACE(trim(BOTH '+' FROM sh.phone), '-', '') = REPLACE(trim(BOTH '+' FROM h.phone), '-', '')
  61. WHERE h.s_id is null AND h.hotel_id not in (29842, 16632)
  62. GROUP BY h.hotel_id HAVING COUNT(1)=1
  63. ) ORDER BY h.country, h.province, h.city, h.district
  64. ;
  65. SELECT h.hotel_id, h.hotel_name, h.link, h.slug, h.country, h.province, h.city, h.district, h.address, h.phone, h.site_url, h.rooms, h.hotel_presentation, h.meeting_facilities,
  66. h.images, h.total_rooms, h.hotel_free_wifi, h.total_meeting_rooms, h.meeting_room_max_sqm, h.meeting_room_max_height, h.projector_resolution, h.total_restaurants,
  67. h.room_quantity, h.meeting_room_quantity, h.meeting_room_facilities, h.restaurant_remark, h.distances, h.brand, h.attachments, h.lon, h.lat,
  68. sh.country as `s_country`, sh.province as `s_province`, sh.city as `s_city`, sh.en_name as `s_name`, sh.en_address as `s_address`, sh.phone as `s_phone`,
  69. sh.hop_id, sh.id as `s_id`, sh.lon as `s_lon`, sh.lat as `s_lat`, sh.loc_type as `s_loc_type`
  70. FROM hotels h
  71. inner join saas_hotel sh on ROUND(6378.138 * 2 * ASIN(SQRT(
  72. POW(SIN((h.lat * PI() / 180 - sh.lat * PI() / 180) / 2), 2) +
  73. COS(h.lat * PI() / 180) * COS(sh.lat * PI() / 180) * POW(SIN((h.lon * PI() / 180 - sh.lon * PI() / 180) / 2), 2)
  74. )) * 1000) <= 200
  75. WHERE h.s_id is null and h.hotel_id in
  76. (
  77. SELECT h.hotel_id FROM hotels h
  78. inner join saas_hotel sh on ROUND(6378.138 * 2 * ASIN(SQRT(
  79. POW(SIN((h.lat * PI() / 180 - sh.lat * PI() / 180) / 2), 2) +
  80. COS(h.lat * PI() / 180) * COS(sh.lat * PI() / 180) * POW(SIN((h.lon * PI() / 180 - sh.lon * PI() / 180) / 2), 2)
  81. )) * 1000) <= 200
  82. WHERE h.s_id is null and h.lon is not null
  83. GROUP BY h.hotel_id HAVING COUNT(1)=1
  84. ) ORDER BY h.country, h.province, h.city, h.district
  85. ;
  86. INSERT INTO hotels_temp
  87. SELECT h.hotel_id, h.hotel_name, h.link, h.slug, h.country, h.province, h.city, h.district, h.address, h.phone, h.site_url, h.rooms, h.hotel_presentation, h.meeting_facilities,
  88. h.images, h.total_rooms, h.hotel_free_wifi, h.total_meeting_rooms, h.meeting_room_max_sqm, h.meeting_room_max_height, h.projector_resolution, h.total_restaurants,
  89. h.room_quantity, h.meeting_room_quantity, h.meeting_room_facilities, h.restaurant_remark, h.distances, h.brand, h.attachments, h.lon, h.lat,
  90. sh.country as `s_country`, sh.province as `s_province`, sh.city as `s_city`, sh.en_name as `s_name`, sh.en_address as `s_address`, sh.phone as `s_phone`,
  91. sh.hop_id, sh.id as `s_id`, sh.lon as `s_lon`, sh.lat as `s_lat`, sh.loc_type as `s_loc_type`
  92. FROM hotels h
  93. inner join saas_hotel sh on sh.hop_id=h.hop_id
  94. WHERE h.s_id is null and h.hop_id is not null and h.hotel_id in
  95. (
  96. SELECT h.hotel_id FROM hotels h
  97. inner join saas_hotel sh on sh.hop_id=h.hop_id
  98. WHERE h.s_id is null and h.hop_id is not null
  99. GROUP BY h.hotel_id HAVING COUNT(1)=1
  100. ) ORDER BY h.country, h.province, h.city, h.district
  101. ;
  102. UPDATE hotels h
  103. inner join hotels_temp a on a.hotel_id=h.hotel_id
  104. SET h.s_country=a.s_country, h.s_province=a.s_province, h.s_city=a.s_city, h.s_name=a.s_name, h.s_address=a.s_address, h.s_phone=a.s_phone,
  105. h.hop_id=a.hop_id, h.s_id=a.s_id, h.s_lon=a.s_lon, h.s_lat=a.s_lat, h.s_loc_type=a.s_loc_type
  106. ;
  107. SELECT
  108. ROUND(6378.138 * 2 * ASIN(SQRT(
  109. POW(SIN((lat * PI() / 180 - s_lat * PI() / 180) / 2), 2) +
  110. COS(lat * PI() / 180) * COS(s_lat * PI() / 180) * POW(SIN((lon * PI() / 180 - s_lon * PI() / 180) / 2), 2)
  111. )) * 1000) AS distance, h.*
  112. FROM hotels h WHERE lon is not null and s_lon is not null order by distance desc;
  113. SELECT SUM(CASE WHEN s_id IS NULL THEN 0 ELSE 1 END) as `mapped`, COUNT(1) as `total` FROM hotels;
  114. SELECT SUM(CASE WHEN s_id IS NULL THEN 0 ELSE 1 END) as `mapped`, COUNT(1) as `total` FROM hotels WHERE country<>'China' or city='Hong Kong' or city='Macau' or province='Taiwan';
  115. SELECT SUM(CASE WHEN s_id IS NULL THEN 0 ELSE 1 END) as `mapped`, COUNT(1) as `total` FROM hotels WHERE country<>'China';
  116. SELECT * FROM hotels WHERE s_id IS NULL and country<>'China' ORDER BY country,province,city;
  117. SELECT s_id, COUNT(1) FROM hotels group by s_id HAVING count(1)>1;
  118. SELECT * FROM hotels h;
  119. SELECT
  120. h.hotel_id as `out_id`, h.hop_id, h.hotel_name, h.country, h.province, h.city, h.district, h.address, h.phone, h.site_url
  121. FROM hotels h WHERE s_id IS NULL ORDER BY country, province, city, district;
  122. SELECT ROUND(6378.138 * 2 * ASIN(SQRT(
  123. POW(SIN((lat * PI() / 180 - s_lat * PI() / 180) / 2), 2) +
  124. COS(lat * PI() / 180) * COS(s_lat * PI() / 180) * POW(SIN((lon * PI() / 180 - s_lon * PI() / 180) / 2), 2)
  125. )) * 1000) AS distance, h.* FROM hotels h WHERE s_id in (976695731874210468,976710868580475183,976710868672750357,976728804883997105)
  126. ORDER BY s_id
  127. ;
  128. UPDATE hotels h
  129. SET h.s_country=NULL, h.s_province=NULL, h.s_city=NULL, h.s_name=NULL, h.s_address=NULL, h.s_phone=NULL,
  130. h.hop_id=NULL, h.s_id=NULL, h.s_lon=NULL, h.s_lat=NULL, h.s_loc_type=NULL
  131. WHERE h.hotel_id in(16666, 18710, 18962, 32776, 31214, 30610, 30638, 24437, 16826)
  132. ;