瀏覽代碼

sql

Signed-off-by: Binren Zhnag <zhangbr@elab-plus.com>
Binren Zhnag 5 年之前
父節點
當前提交
60e79eeb3a
共有 1 個文件被更改,包括 27 次插入25 次删除
  1. 27 25
      report_push.py

+ 27 - 25
report_push.py

@@ -182,17 +182,17 @@ class ReportPush(object):
 
     #  1.默认值/001_大麦/项目排行榜/小程序排行榜TOP_N
     sql_2_1 = """
-        SELECT
-        a.house_id,
-        a.house_name,
-        ifnull(SUM(a.pv), 0),
-        SUM(a.uv),
-        SUM(a.new_cust_num),
-        SUM(a.wx_num)
-        from
-            (SELECT
-                a.*, 
-                b.house_name,
+            SELECT
+                    a.house_id,
+                    a.house_name,
+                    ifnull(SUM(a.pv), 0),
+                    SUM(a.uv),
+                    SUM(a.new_cust_num),
+                    SUM(a.wx_num)
+                    from
+                        (
+            SELECT
+                a.*, b.house_name,
                 c.interested_num,
                 d.wx_num,
                 e.new_cust_num
@@ -219,7 +219,7 @@ class ReportPush(object):
             LEFT JOIN (
                 SELECT
                     house_id,
-                    count(*) interested_num
+                    count(DISTINCT customer_id) interested_num
                 FROM
                     f_interested_custlist
                 WHERE
@@ -231,11 +231,11 @@ class ReportPush(object):
             LEFT JOIN (
                 SELECT
                     house_id,
-                    count(*) wx_num
+                    count(DISTINCT mobile) wx_num
                 FROM
                     f_customer_dynamic
                 WHERE
-                    dynamic = 1
+                    dynamic IN (1, 2, 4)
                 AND report_d >= %s
                 AND report_d <= %s
                 GROUP BY
@@ -244,21 +244,23 @@ class ReportPush(object):
             LEFT JOIN (
                 SELECT
                     house_id,
-                    count(*) new_cust_num
+                    count(DISTINCT user_id) new_cust_num
                 FROM
                     d_user
                 WHERE
-                    created >= %s
-                AND created <= %s
-                	AND source IN (1, 2, 4, 10)
+                    source IN (1, 2, 3, 4, 10)
+                AND created >= %s
+                AND created < DATE_ADD(
+                    %s, INTERVAL 1 DAY
+                )
                 GROUP BY
                     house_id
-            ) e ON a.house_id = e.house_id
-            ) a
-        GROUP BY
-            a.house_id,
-            a.house_name
-        order by a.pv desc
+            ) e ON a.house_id = e.house_id)
+            a
+                    GROUP BY
+                        a.house_id,
+                        a.house_name
+                    order by a.pv desc
     """
 
     # 2.默认值/006_大麦(集团)/集团项目排行榜v1.3/集团排行榜
@@ -452,7 +454,7 @@ class ReportPush(object):
     """
 
     def __init__(self, db_name):
-        self.db = MysqlDB(db_name)
+        self.db = MysqlDB(db_name, db_type=1)
 
     mails = ['1285211525@qq.com', 'lijm@elab-plus.com', 'xuanxc@elab-plus.com']