Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1.  
  2. select a.week_date,a.aff_id,a.aff_name, a.booker_cc1, a.tns, a.gross_rn, round(a.gross_ttv,0) as gross_ttv, a.is_global from (
  3. select
  4. subdate(date_format(r.created, "%Y-%m-%d"), weekday(r.created)) as week_date,
  5. r.affiliate_id as aff_id, a.name as aff_name, r.booker_cc1 as booker_cc1,
  6. count(distinct r.id) as tns,
  7. sum(roomnights) as gross_rn, sum(r.price_euro) as gross_ttv,
  8. if(count(distinct r.id) > 0,'gb','') as is_global
  9. from Reservation r
  10. left join B_Affiliate a on a.id=r.affiliate_id
  11. where r.affiliate_id in (324340,
  12. 323128,
  13. 323127,
  14. 323126,
  15. 323125,
  16. 323124,
  17. 323592,
  18. 323593,
  19. 375450,
  20. 846004,
  21. 394788,
  22. 394271,
  23. 394789,
  24. 394787,
  25. 396670,
  26. 396671,
  27. 1373045,
  28. 396674,
  29. 399948,
  30. 399949,
  31. 801059,
  32. 801382,
  33. 801386,
  34. 801387,
  35. 801391,
  36. 1137797,
  37. 801392,
  38. 801393,
  39. 801394,
  40. 801395,
  41. 801396,
  42. 1559275,
  43. 801399,
  44. 801404,
  45. 801406,
  46. 808432,
  47. 808433,
  48. 808434,
  49. 808435,
  50. 1631702,
  51. 808437,
  52. 811130,
  53. 1139656,
  54. 1128032,
  55. 1139660,
  56. 1139661,
  57. 1139664,
  58. 1139666,
  59. 1139669,
  60. 1139672,
  61. 1139675,
  62. 1139676,
  63. 1139678,
  64. 1139682,
  65. 1139686,
  66. 1139689,
  67. 1139696,
  68. 1139697,
  69. 1139698,
  70. 1139699,
  71. 1139701,
  72. 1139703,
  73. 1139706,
  74. 1139714,
  75. 1139716,
  76. 1194862,
  77. 1346052,
  78. 1194867,
  79. 1224988,
  80. 1224987,
  81. 1231116,
  82. 1231130,
  83. 1267312,
  84. 1267313,
  85. 1267315,
  86. 1267316,
  87. 1267317,
  88. 1267318,
  89. 1267319,
  90. 1267320,
  91. 1267321,
  92. 1267323,
  93. 1267326,
  94. 1267330,
  95. 1267333,
  96. 1291764,
  97. 1369234
  98. )
  99. and r.created BETWEEN '2019-01-01' and '2019-12-16'
  100. group by 1,2,4 ) a
  101. union select b.week_date,b.aff_id,b.aff_name, b.booker_cc1, b.tns, b.gross_rn, b.gross_ttv, '' as is_global from (select
  102. subdate(date_format(r.created, "%Y-%m-%d"), weekday(r.created)) as week_date,
  103. r.affiliate_id as aff_id, a.name as aff_name, r.booker_cc1 as booker_cc1,
  104. count(distinct r.id) * -1 as tns,
  105. sum(roomnights) * -1 as gross_rn, sum(r.price_euro) * -1 as gross_ttv
  106. from Reservation r
  107. left join B_Affiliate a on a.id=r.affiliate_id
  108. where r.affiliate_id in (324340,
  109. 323128,
  110. 323127,
  111. 323126,
  112. 323125,
  113. 323124,
  114. 323592,
  115. 323593,
  116. 375450,
  117. 846004,
  118. 394788,
  119. 394271,
  120. 394789,
  121. 394787,
  122. 396670,
  123. 396671,
  124. 1373045,
  125. 396674,
  126. 399948,
  127. 399949,
  128. 801059,
  129. 801382,
  130. 801386,
  131. 801387,
  132. 801391,
  133. 1137797,
  134. 801392,
  135. 801393,
  136. 801394,
  137. 801395,
  138. 801396,
  139. 1559275,
  140. 801399,
  141. 801404,
  142. 801406,
  143. 808432,
  144. 808433,
  145. 808434,
  146. 808435,
  147. 1631702,
  148. 808437,
  149. 811130,
  150. 1139656,
  151. 1128032,
  152. 1139660,
  153. 1139661,
  154. 1139664,
  155. 1139666,
  156. 1139669,
  157. 1139672,
  158. 1139675,
  159. 1139676,
  160. 1139678,
  161. 1139682,
  162. 1139686,
  163. 1139689,
  164. 1139696,
  165. 1139697,
  166. 1139698,
  167. 1139699,
  168. 1139701,
  169. 1139703,
  170. 1139706,
  171. 1139714,
  172. 1139716,
  173. 1194862,
  174. 1346052,
  175. 1194867,
  176. 1224988,
  177. 1224987,
  178. 1231116,
  179. 1231130,
  180. 1267312,
  181. 1267313,
  182. 1267315,
  183. 1267316,
  184. 1267317,
  185. 1267318,
  186. 1267319,
  187. 1267320,
  188. 1267321,
  189. 1267323,
  190. 1267326,
  191. 1267330,
  192. 1267333,
  193. 1291764,
  194. 1369234
  195. )
  196. and r.status in ('cancelled_by_guest', 'cancelled_by_hotel')
  197. and r.created BETWEEN '2019-01-01' and '2019-12-16'
  198. group by 1,2,4 ) b
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement