Browse Source

report_push: 修改slq

Signed-off-by: Binren Zhnag <zhangbr@elab-plus.com>
Binren Zhnag 5 years ago
parent
commit
93890495c3
1 changed files with 76 additions and 71 deletions
  1. 76 71
      report_push.py

+ 76 - 71
report_push.py

@@ -263,85 +263,90 @@ class ReportPush(object):
 
 
     # 2.默认值/006_大麦(集团)/集团项目排行榜v1.3/集团排行榜
     # 2.默认值/006_大麦(集团)/集团项目排行榜v1.3/集团排行榜
     sql_2_2 = """
     sql_2_2 = """
-                SELECT
+                select 
+                     x.brand_id,
+                        x.house_id,
+                        x.house_name,
+                        x.pv,
+                    x.uv,
+                    x.new_cust,
+                    x.shouquan_cust
+                     from (
+                    SELECT
+                        c.pv,
+                        c.uv,
+                        a.brand_id,
                         a.house_id,
                         a.house_id,
                         a.house_name,
                         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
-                FROM
-                    (
+                        a.brand_name,
+                        ifnull(b.house_layout_num, 0) house_layout_num,
+                        ifnull(d.launch_time, '--') launch_time,
+                        c.new_cust,
+                        c.shouquan_cust,
+                        c.revisit_cust
+                    FROM
+                        (
+                            SELECT
+                                brand_id,
+                                ifnull(house_id, '0') house_id,
+                                sum(pv) pv,
+                                count(DISTINCT brand_user_id) uv,
+                                count(
+                                    DISTINCT CASE
+                                    WHEN is_new_user = 1 THEN
+                                        brand_user_id
+                                    END
+                                ) new_cust,
+                                count(
+                                    DISTINCT CASE
+                                    WHEN is_shouquan_user = 1 THEN
+                                        brand_user_id
+                                    END
+                                ) shouquan_cust,
+                                count(
+                                    DISTINCT CASE
+                                    WHEN is_new_user = 0 THEN
+                                        brand_user_id
+                                    END
+                                ) revisit_cust
+                            FROM
+                                a_behavior_brand_mini_day
+                            WHERE
+                                report_d >= %s
+                            AND report_d <= %s
+                            GROUP BY
+                                brand_id,
+                                ifnull(house_id, '0')
+                        ) c
+                    LEFT JOIN (
                         SELECT
                         SELECT
                             house_id,
                             house_id,
-                            count(
-                                DISTINCT ifnull(user_id, idfa)
-                            ) uv,
-                            sum(session_times) session_times,
-                            sum(sum_session_time) sum_session_time,
-                            sum(pv) pv,
-                            sum(page_num) page_num
+                            count(1) house_layout_num
                         FROM
                         FROM
-                            a_idfa_behavior_sum
+                            d_content_layout
                         WHERE
                         WHERE
-                            report_d >= %s
-                        AND report_d <= %s
+                            `status` = '1'
+                        AND house_id <> 1
                         GROUP BY
                         GROUP BY
                             house_id
                             house_id
-                    ) a
-                JOIN d_house b ON a.house_id = b.house_id
-                LEFT JOIN (
-                    SELECT
-                        house_id,
-                        count(DISTINCT customer_id) interested_num
-                    FROM
-                        f_interested_custlist
-                    WHERE
-                        report_d >= %s
-                    AND report_d <= %s
-                    GROUP BY
-                        house_id
-                ) c ON a.house_id = c.house_id
-                LEFT JOIN (
-                    SELECT
-                        house_id,
-                        count(DISTINCT mobile) wx_num
-                    FROM
-                        f_customer_dynamic
-                    WHERE
-                        dynamic IN (1, 2, 4)
-                    AND report_d >= %s
-                    AND report_d <= %s
-                    GROUP BY
-                        house_id
-                ) d ON a.house_id = d.house_id
-                LEFT JOIN (
-                    SELECT
-                        house_id,
-                        count(DISTINCT user_id) new_cust_num
-                    FROM
-                        d_user
-                    WHERE
-                        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
+                        UNION ALL
+                            SELECT
+                                bb.brand_id house_id,
+                                count(1) house_layout_num
+                            FROM
+                                d_content_layout aa
+                            JOIN d_house bb ON aa.house_id = bb.house_id
+                            WHERE
+                                aa.`status` = '1'
+                            AND bb. STATUS = '1'
+                            AND aa.house_id <> 1
+                            GROUP BY
+                                bb.brand_id
+                    ) b ON c.house_id = b.house_id
+                    JOIN d_house a ON a.house_id = c.house_id
+                    AND a.brand_id = c.brand_id
+                    LEFT JOIN d_house_attr d ON c.house_id = d.house_id
+                    AND c.brand_id = d.brand_id ) x
     """
     """
 
 
     # 默认值/001_大麦/场景_用户来源渠道/用户来源渠道—明细
     # 默认值/001_大麦/场景_用户来源渠道/用户来源渠道—明细