sql.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. class Sql:
  2. # 获取项目的城市信息
  3. sql_1 = """
  4. select IFNULL(brand_id, -1), house_id, house_name, city from d_house a where brand_id = '13' and house_id != '13' order by house_id
  5. """
  6. # 根据任务id获取推送客户信息
  7. sql_2 = """
  8. select a.task_key, b.customer_type, b.name, b.mail, b.house_or_region, a.customer_id, GROUP_CONCAT(c.house_or_brand_id) as ids
  9. from report_task_info a left join report_push_customer_info b on b.id = a.customer_id
  10. left join report_customer_authority_info c on b.id = c.customer_id
  11. where a.task_key = %s and a.status = b.status = c.status = 1
  12. group by a.task_key, b.customer_type, b.name, b.mail, b.house_or_region, a.customer_id
  13. """
  14. # 1:总浏览量
  15. #
  16. # 集团部分+项目部分!!!
  17. # ----项目PV--权限项目范围内,求和
  18. # 参数:时间区间 和 项目列表
  19. sql_3 = """
  20. SELECT SUM(pv) AS pv1 FROM a_idfa_behavior_sum
  21. WHERE report_d >= %s and report_d <= %s AND house_id IN %s
  22. """
  23. # ----集团PV--权限项目范围内,求和
  24. # 参数:数据区间和项目列表
  25. sql_4 = """
  26. SELECT SUM(pv) AS pav2 FROM a_behavior_brand_mini_day
  27. WHERE report_d >= %s and report_d <= %s AND house_id IN %s
  28. """
  29. # 2:总浏览人数
  30. #
  31. # 参数,数据区间, 项目列表
  32. sql_5 = """
  33. SELECT
  34. count(
  35. DISTINCT IFNULL(mobile, user_id)
  36. ) as people
  37. FROM
  38. (
  39. SELECT
  40. A.user_id,
  41. B.mobile
  42. FROM
  43. a_idfa_behavior_sum A
  44. LEFT JOIN d_user B ON A.user_id = B.user_id
  45. WHERE
  46. A.report_d >= %s and A.report_d <= %s
  47. AND A.house_id IN %s
  48. UNION
  49. SELECT
  50. A.brand_user_id AS user_id,
  51. B.mobile
  52. FROM
  53. a_behavior_brand_mini_day A
  54. LEFT JOIN a_brand_app_customer B ON A.brand_user_id = B.brand_customer_id
  55. WHERE
  56. A.report_d >= %s and A.report_d <= %s
  57. AND A.house_id IN %s
  58. ) t1
  59. """
  60. # 3:新增获客
  61. sql_6 = """
  62. SELECT
  63. count(
  64. DISTINCT IFNULL(mobile, user_id)
  65. )
  66. FROM
  67. (
  68. SELECT
  69. user_id,
  70. mobile,
  71. created
  72. FROM
  73. d_user
  74. WHERE
  75. created >= %s
  76. AND created <= %s
  77. AND house_id IN %s
  78. AND source ='3'
  79. UNION
  80. SELECT
  81. brand_customer_id AS user_id,
  82. mobile,
  83. rlat_created
  84. FROM
  85. a_brand_app_customer_house_rlat
  86. WHERE
  87. rlat_created >= %s
  88. AND rlat_created <= %s
  89. AND rlat_house_id IN %s
  90. AND cust_house_flag ='1'
  91. ) t1
  92. """
  93. # 4:新增获电
  94. sql_7 = """
  95. SELECT
  96. COUNT(DISTINCT mobile)
  97. FROM
  98. (
  99. SELECT
  100. user_id,
  101. mobile,
  102. wx_phone_time AS created
  103. FROM
  104. d_user
  105. WHERE
  106. wx_phone_time >= %s
  107. AND wx_phone_time <= %s
  108. AND house_id IN %s
  109. and source = '3'
  110. UNION
  111. SELECT
  112. brand_customer_id,
  113. mobile,
  114. houdian_time AS created
  115. FROM
  116. (
  117. SELECT
  118. *,
  119. CASE
  120. WHEN rlat_created > shouquan_time THEN
  121. rlat_created
  122. ELSE
  123. shouquan_time
  124. END AS houdian_time
  125. FROM
  126. a_brand_app_customer_house_rlat
  127. WHERE
  128. mobile IS NOT NULL
  129. AND rlat_house_id IN %s
  130. AND cust_house_flag = '1'
  131. ) t1
  132. WHERE
  133. houdian_time >= %s
  134. AND houdian_time <= %s
  135. ) t1
  136. """
  137. # hosue_id, type, count
  138. sql_8 = """
  139. select house_id, type, COUNT(DISTINCT customer_mobile) from f_dm_jianye_allagent_day where report_d >= %s and report_d <= %s group by house_id, type
  140. """
  141. sql_9 = """
  142. SELECT house_id, visit_new_uv_dtd FROM a_brand_customer_share_dtd where brand_id ='13' and report_d >= %s and report_d <= %s order by report_d
  143. """
  144. sql_10 = """
  145. select type, COUNT(DISTINCT customer_mobile) from f_dm_jianye_allagent_day where report_d >= %s and report_d <= %s group by type
  146. """
  147. sql_11 = """"
  148. select a.house_or_region, min(b.house_or_brand_id), sum(a.name) from report_push_customer_info a left join report_customer_authority_info b on a.id = b.customer_id group by house_or_region
  149. """
  150. sql_12 = """
  151. insert into report_push_log(name, mail, report_name, push_time, send_status, status, error_message) values(%s, %s, %s, now(), %s, 1, %s)
  152. """
  153. sql_13 = """
  154. SELECT
  155. x.brand_id,
  156. x.house_id,
  157. x.house_name,
  158. ifnull(x.pv, 0),
  159. x.uv,
  160. x.new_cust,
  161. x.shouquan_cust
  162. FROM
  163. (
  164. SELECT
  165. c.pv,
  166. c.uv,
  167. a.brand_id,
  168. a.house_id,
  169. a.house_name,
  170. a.brand_name,
  171. ifnull(b.house_layout_num, 0) house_layout_num,
  172. ifnull(d.launch_time, '--') launch_time,
  173. c.new_cust,
  174. c.shouquan_cust,
  175. c.revisit_cust
  176. FROM
  177. (
  178. SELECT
  179. brand_id,
  180. ifnull(house_id, '0') house_id,
  181. sum(pv) pv,
  182. count(DISTINCT brand_user_id) uv,
  183. count(
  184. DISTINCT CASE
  185. WHEN is_new_user = 1 THEN
  186. brand_user_id
  187. END
  188. ) new_cust,
  189. count(
  190. DISTINCT CASE
  191. WHEN is_shouquan_user = 1 THEN
  192. brand_user_id
  193. END
  194. ) shouquan_cust,
  195. count(
  196. DISTINCT CASE
  197. WHEN is_new_user = 0 THEN
  198. brand_user_id
  199. END
  200. ) revisit_cust
  201. FROM
  202. a_behavior_brand_mini_day
  203. WHERE
  204. report_d >= %s
  205. AND report_d <= %s
  206. GROUP BY
  207. brand_id,
  208. ifnull(house_id, '0')
  209. ) c
  210. LEFT JOIN (
  211. SELECT
  212. house_id,
  213. count(1) house_layout_num
  214. FROM
  215. d_content_layout
  216. WHERE
  217. `status` = '1'
  218. AND house_id <> 1
  219. GROUP BY
  220. house_id
  221. UNION ALL
  222. SELECT
  223. bb.brand_id house_id,
  224. count(1) house_layout_num
  225. FROM
  226. d_content_layout aa
  227. JOIN d_house bb ON aa.house_id = bb.house_id
  228. WHERE
  229. aa.`status` = '1'
  230. AND bb. STATUS = '1'
  231. AND aa.house_id <> 1
  232. GROUP BY
  233. bb.brand_id
  234. ) b ON c.house_id = b.house_id
  235. JOIN d_house a ON a.house_id = c.house_id
  236. AND a.brand_id = c.brand_id
  237. LEFT JOIN d_house_attr d ON c.house_id = d.house_id
  238. AND c.brand_id = d.brand_id
  239. ) x
  240. """
  241. sql_14 = """
  242. select a.id , a.`name`, a.mail, a.customer_type, a.house_or_region, GROUP_CONCAT(b.house_or_brand_id)
  243. from report_push_customer_info a
  244. left join report_customer_authority_info b on a.id = b.customer_id
  245. where a.id = %s and a.status = 1 and b.status = 1
  246. group by a.id , a.`name`, a.mail, a.customer_type, a.house_or_region
  247. """
  248. sql_15 = """
  249. select * from d_jianye_house_city_region_rlat
  250. """
  251. sql_16 = """
  252. SELECT b.region, b.city, a.house_name, a.advi_name, a.mobile, a.org_name, IFNULL(a.fx_mobile,0), IFNULL(a.zc_mobile, 0), IFNULL(a.bb_mobile, 0) FROM f_dm_jianye_agent_house_day a left join d_jianye_house_city_region_rlat b on a.house_id = b.house_id where a.report_d = %s and a.house_id in %s order by a.org_name, CAST(a.fx_mobile AS SIGNED) desc
  253. """
  254. sql_17 = """
  255. SELECT b.region, b.city, a.house_name, a.advi_name, a.mobile, a.org_name, IFNULL(a.fx_mobile,0), IFNULL(a.zc_mobile, 0), IFNULL(a.bb_mobile, 0) FROM f_dm_jianye_agent_house_month a left join d_jianye_house_city_region_rlat b on a.house_id = b.house_id where a.report_d = %s and a.house_id in %s order by a.org_name, CAST(a.fx_mobile AS SIGNED) desc
  256. """
  257. sql_18 = """
  258. SELECT b.region, b.city, a.house_name, a.advi_name, a.mobile, a.org_name, IFNULL(a.fx_mobile,0), IFNULL(a.zc_mobile, 0), IFNULL(a.bb_mobile, 0) FROM f_dm_jianye_agent_house_all a left join d_jianye_house_city_region_rlat b on a.house_id = b.house_id where a.report_d = %s and a.house_id in %s order by a.org_name, CAST(a.fx_mobile AS SIGNED) desc
  259. """
  260. if __name__ == '__main__':
  261. print(len('222'))