renyupeng 2 anos atrás
pai
commit
16ac5c65df

+ 36 - 0
sql/DesignerInUserCompanyCost.sql

@@ -0,0 +1,36 @@
+       select
+       a.account_id as `账户 `,
+       signature   as `视频md5`,
+       photo_url as `视频链接`,
+       video_name as `视频名称`,
+       project_name   `项目名称`,
+       clip_name      `剪辑`,
+       plan_name      `编导`,
+       shot_name      `拍摄`,
+       leader_name   `负责人`,
+       sum(charge) as `消耗`,
+       case when channel_type =0 then '内部' when channel_type=1 then '塑造' else '-' end as `渠道`
+from (select account_id,
+             signature,
+             channel_type,
+             project_name,
+             leader_name,
+             plan_name,
+             clip_name,
+             shot_name,
+             charge,
+             clip_company_id,
+             photo_url,
+             video_name
+      from application.kuaishou_material_video_report_daily_dw
+      where stat_date between 20220401 and 20220430) a
+         inner join (
+    select account_id
+    from `jeecg-boot`.ctop_user_allocation
+    where user_id in (
+        select user_id from `jeecg-boot`.user_company where company_id = 'd57fecdcf7a94d009736d9c850731582'
+    )
+) b
+                   on a.account_id = b.account_id
+ where clip_company_id='1648c7ceb4d449a9a13fbed7a8d9976c'
+group by signature, a.account_id

+ 341 - 0
sql/头条剪辑排名.sql

@@ -0,0 +1,341 @@
+select
+       concat(date_format(date_sub(:date, interval 6 day), '%Y%m%d') ,'-',date_format(:date, '%Y%m%d')) as stat_datetime,
+       round(row_number() over (order by clip_cost desc ),0) as rn,
+       clip_name,
+       clip_cost,
+       ifnull(hot_num,0) as hot_num,
+       ifnull(hot_cost,0) as hot_cost,
+       concat(round(ifnull(hot_num/material_num*100,0),2),'%') as hot_rate,
+       ifnull(material_num,0) as material_num,
+       ifnull(plan_num,0) as plan_num,
+       ifnull(hotplancount,0) as  hotplancount,
+       ifnull(man_num,0) as man_num,
+       ifnull(hotmancount,0) as hotmancount
+from (
+         select clip_name,
+                sum(clip_cost) as clip_cost,
+                sumcost,
+                sum(hot_num)      as hot_num,
+                sum(material_num) as material_num,
+                sum(hot_cost)     as hot_cost,
+                sum(man_num)      as man_num,
+                sum(hotmancount)  as hotmancount,
+                sum(plan_num)     as plan_num,
+                sum(hotplancount) as hotplancount
+         from (
+                  select info.clip_id,
+                         case
+                             when info.clip_name like '%汇创%' then replace(clip_name, '(汇创)', '')
+                             else clip_name end as clip_name,
+                         info.clip_cost,
+                         info.sumcost,
+                         hot_num,
+                         hot_cost,
+                         material_num,
+                         man_num,
+                         hotmancount,
+                         plan_num,
+                         hotplancount
+                  from (select clip_id, clip_name, clip_cost, sumcost
+                        from (select clip_id, clip_name, sum(cost) as clip_cost
+                              from application.bytedance_material_video_report_daily_dw
+                              where stat_datetime between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')
+                                and clip_company_id in
+                                    ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                and clip_id is not null
+                              group by clip_id, clip_name) a
+                                 join (select sum(cost) as sumcost
+                                       from application.bytedance_material_video_report_daily_dw
+                                       where stat_datetime between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')
+                                         and clip_company_id in
+                                             ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                         and clip_id is not null) b) info
+
+
+                           left join (
+                      select clip_id, count(1) as material_num
+                      from `jeecg-boot`.ctop_material_ascription
+                      where create_time between date_format(date_sub(:date, interval 6 day), '%Y-%m-%d')
+                          and date_format(date_sub(:date, interval -1 day), '%Y-%m-%d')
+                        and clip_id in (select user_id
+                                          from `jeecg-boot`.user_company
+                                          where company_id in
+                                                ('d57fecdcf7a94d009736d9c850731582',
+                                                 '5e46b5dea3d740eeb8ff1a2895015a4b'))
+                      group by clip_id) b
+                                     on info.clip_id = b.clip_id
+                           left join(
+                      select clip_id, sum(hot_num) as hot_num, sum(hot_cost) as hot_cost
+                      from (
+                               select b.clip_id, count(1) as hot_num, sum(hot_cost) as hot_cost
+                               from (select signature
+                                     from application.hot_material
+                                     where media_id = 1
+                                       and hot_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')) a
+                                        inner join
+                                    (select material_id, clip_id
+                                     from `jeecg-boot`.ctop_material_ascription
+                                     where clip_id in (select user_id
+                                                         from `jeecg-boot`.user_company
+                                                         where company_id in
+                                                               ('d57fecdcf7a94d009736d9c850731582',
+                                                                '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                     )) b
+                                    on a.signature = b.material_id
+                                        left join(
+                                   select *
+                                   from application.hot_material_two_week_cost
+                                   where media_id = 1
+                               ) c
+                                                 on a.signature = c.signature
+                                        left join (select material_id, parent_id, parent_name
+                                                   from application.app_material_tag_busi_info
+                                                   where tag_category_id = 1
+                                                   group by material_id, parent_id) d
+                                                  on a.signature = d.material_id
+                               group by clip_id, a.signature) t
+                      group by clip_id) c
+                                    on info.clip_id = c.clip_id
+                           left join (
+                      select clip_id, parent_id, count(distinct tag.material_id) as man_num
+                      from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+
+                      where create_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d')
+                          and date_format(date_sub(:date, interval -1 day), '%Y%m%d')
+                        and tag_category_id = 1
+                        and parent_id = 60155
+                      group by clip_id, parent_id) d
+                                     on info.clip_id = d.clip_id
+                           left join
+                       (select clip_id, parent_id, count(distinct tag.material_id)  as plan_num
+                        from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+                        where create_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d')
+                            and date_format(date_sub(:date, interval -1 day), '%Y%m%d')
+                          and tag_category_id = 1
+                          and parent_id = 60156
+                        group by clip_id, parent_id) e
+                       on info.clip_id = e.clip_id
+
+                           left join
+                       (select clip_id, count(distinct signature) as hotmancount
+                        from (select signature
+                              from application.hot_material
+                              where media_id = 1
+                                and hot_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')) a
+                                 inner join
+                             (select clip_id, tag.material_id
+                              from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+                              where tag_category_id = 1
+                                and parent_id = 60155
+                                and clip_id in (select user_id
+                                                  from `jeecg-boot`.user_company
+                                                  where company_id in
+                                                        ('d57fecdcf7a94d009736d9c850731582',
+                                                         '5e46b5dea3d740eeb8ff1a2895015a4b'))) b
+                             on a.signature = b.material_id
+                        group by clip_id) f
+                       on info.clip_id = f.clip_id
+                           left join
+                       (select clip_id, count(distinct signature) as hotplancount
+                        from (select signature
+                              from application.hot_material
+                              where media_id = 1
+                                and hot_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')) a
+                                 inner join
+                             (select clip_id, tag.material_id
+                              from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+                              where tag_category_id = 1
+                                and parent_id = 60156
+                                and clip_id in (select user_id
+                                                  from `jeecg-boot`.user_company
+                                                  where company_id in
+                                                        ('d57fecdcf7a94d009736d9c850731582',
+                                                         '5e46b5dea3d740eeb8ff1a2895015a4b'))) b
+                             on a.signature = b.material_id
+                        group by clip_id) i
+                       on info.clip_id = i.clip_id) t
+         group by clip_name, sumcost) t;
+
+
+
+
+
+
+
+
+
+
+
+select
+       concat(date_format(date_sub(:date, interval 6 day), '%Y%m%d') ,'-',date_format(:date, '%Y%m%d')) as stat_datetime,
+       '' rn,
+      '汇总' clip_name,
+       sum(clip_cost) as clip_cost,
+       ifnull(sum(hot_num),0) as hot_num,
+       ifnull(sum(hot_cost),0) as hot_cost,
+       concat(round(ifnull(sum(hot_num)/sum(material_num)*100,0),2),'%') as hot_rate,
+       ifnull(sum(material_num),0) as material_num,
+       ifnull(sum(plan_num),0) as plan_num,
+       ifnull(sum(hotplancount),0) as  hotplancount,
+       ifnull(sum(man_num),0) as man_num,
+       ifnull(sum(hotmancount),0) as hotmancount
+from (
+         select clip_name,
+                sum(clip_cost) as clip_cost,
+                sumcost,
+                sum(hot_num)      as hot_num,
+                sum(material_num) as material_num,
+                sum(hot_cost)     as hot_cost,
+                sum(man_num)      as man_num,
+                sum(hotmancount)  as hotmancount,
+                sum(plan_num)     as plan_num,
+                sum(hotplancount) as hotplancount
+         from (
+                  select info.clip_id,
+                         case
+                             when info.clip_name like '%汇创%' then replace(clip_name, '(汇创)', '')
+                             else clip_name end as clip_name,
+                         info.clip_cost,
+                         info.sumcost,
+                         hot_num,
+                         hot_cost,
+                         material_num,
+                         man_num,
+                         hotmancount,
+                         plan_num,
+                         hotplancount
+                  from (select clip_id, clip_name, clip_cost, sumcost
+                        from (select clip_id, clip_name, sum(cost) as clip_cost
+                              from application.bytedance_material_video_report_daily_dw
+                              where stat_datetime between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')
+                                and clip_company_id in
+                                    ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                and clip_id is not null
+                              group by clip_id, clip_name) a
+                                 join (select sum(cost) as sumcost
+                                       from application.bytedance_material_video_report_daily_dw
+                                       where stat_datetime between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')
+                                         and clip_company_id in
+                                             ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                         and clip_id is not null) b) info
+
+
+                           left join (
+                      select clip_id, count(1) as material_num
+                      from `jeecg-boot`.ctop_material_ascription
+                      where create_time between date_format(date_sub(:date, interval 6 day), '%Y-%m-%d')
+                          and date_format(date_sub(:date, interval -1 day), '%Y-%m-%d')
+                        and clip_id in (select user_id
+                                          from `jeecg-boot`.user_company
+                                          where company_id in
+                                                ('d57fecdcf7a94d009736d9c850731582',
+                                                 '5e46b5dea3d740eeb8ff1a2895015a4b'))
+                      group by clip_id) b
+                                     on info.clip_id = b.clip_id
+                           left join(
+                      select clip_id, sum(hot_num) as hot_num, sum(hot_cost) as hot_cost
+                      from (
+                               select b.clip_id, count(1) as hot_num, sum(hot_cost) as hot_cost
+                               from (select signature
+                                     from application.hot_material
+                                     where media_id = 1
+                                       and hot_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')) a
+                                        inner join
+                                    (select material_id, clip_id
+                                     from `jeecg-boot`.ctop_material_ascription
+                                     where clip_id in (select user_id
+                                                         from `jeecg-boot`.user_company
+                                                         where company_id in
+                                                               ('d57fecdcf7a94d009736d9c850731582',
+                                                                '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                     )) b
+                                    on a.signature = b.material_id
+                                        left join(
+                                   select *
+                                   from application.hot_material_two_week_cost
+                                   where media_id = 1
+                               ) c
+                                                 on a.signature = c.signature
+                                        left join (select material_id, parent_id, parent_name
+                                                   from application.app_material_tag_busi_info
+                                                   where tag_category_id = 1
+                                                   group by material_id, parent_id) d
+                                                  on a.signature = d.material_id
+                               group by clip_id, a.signature) t
+                      group by clip_id) c
+                                    on info.clip_id = c.clip_id
+                           left join (
+                      select clip_id, parent_id, count(distinct tag.material_id) as man_num
+                      from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+
+                      where create_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d')
+                          and date_format(date_sub(:date, interval -1 day), '%Y%m%d')
+                        and tag_category_id = 1
+                        and parent_id = 60155
+                      group by clip_id, parent_id) d
+                                     on info.clip_id = d.clip_id
+                           left join
+                       (select clip_id, parent_id, count(distinct tag.material_id)  as plan_num
+                        from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+                        where create_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d')
+                            and date_format(date_sub(:date, interval -1 day), '%Y%m%d')
+                          and tag_category_id = 1
+                          and parent_id = 60156
+                        group by clip_id, parent_id) e
+                       on info.clip_id = e.clip_id
+
+                           left join
+                       (select clip_id, count(distinct signature) as hotmancount
+                        from (select signature
+                              from application.hot_material
+                              where media_id = 1
+                                and hot_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')) a
+                                 inner join
+                             (select clip_id, tag.material_id
+                              from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+                              where tag_category_id = 1
+                                and parent_id = 60155
+                                and clip_id in (select user_id
+                                                  from `jeecg-boot`.user_company
+                                                  where company_id in
+                                                        ('d57fecdcf7a94d009736d9c850731582',
+                                                         '5e46b5dea3d740eeb8ff1a2895015a4b'))) b
+                             on a.signature = b.material_id
+                        group by clip_id) f
+                       on info.clip_id = f.clip_id
+                           left join
+                       (select clip_id, count(distinct signature) as hotplancount
+                        from (select signature
+                              from application.hot_material
+                              where media_id = 1
+                                and hot_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')) a
+                                 inner join
+                             (select clip_id, tag.material_id
+                              from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+                              where tag_category_id = 1
+                                and parent_id = 60156
+                                and clip_id in (select user_id
+                                                  from `jeecg-boot`.user_company
+                                                  where company_id in
+                                                        ('d57fecdcf7a94d009736d9c850731582',
+                                                         '5e46b5dea3d740eeb8ff1a2895015a4b'))) b
+                             on a.signature = b.material_id
+                        group by clip_id) i
+                       on info.clip_id = i.clip_id) t
+         group by clip_name, sumcost) t

+ 176 - 0
sql/头条大盘.sql

@@ -0,0 +1,176 @@
+-- 运营
+select :date as date,
+       realname as user_name,
+       count as account_num,
+       cost,
+       concat(round((cost-yes_week_cost)/yes_week_cost*100,2),'%') as cost_rate,
+       effect_num,
+       new_campaign_num,
+       new_ad_num,
+       quarter_cost
+from (
+    select user_id,count(1) as count,sum(cost) as cost from (
+    select user_id, account_id, sum(cost) as cost
+      from application.bytedance_advertiser_report_daily_dw
+      where stat_datetime between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')
+        and cost > 0
+    and company_id='d57fecdcf7a94d009736d9c850731582'
+    and user_id in(
+        select id from `jeecg-boot`.sys_user where leader_id='c52551687c524a96a3904658a35f0f26'
+        union all
+        select id from `jeecg-boot`.sys_user where id='c52551687c524a96a3904658a35f0f26'
+          )
+    group by user_id,account_id)t
+    group by user_id) a
+         left join (
+    select user_id,
+           sum(cost) as yes_week_cost
+    from application.bytedance_advertiser_report_daily_dw
+    where stat_datetime between date_format(date_sub(:date, interval 13 day), '%Y%m%d') and date_format(date_sub(:date, interval 7 day), '%Y%m%d')
+      and cost > 0
+    group by user_id
+) b
+                   on a.user_id = b.user_id
+         left join (
+    select user_id,
+           sum(new_effect_num)       as effect_num,
+           sum(new_campaign_num) as new_campaign_num,
+           sum(new_ad_num)       as new_ad_num
+    from application.app_bytedance_account_base_info_d
+    where stat_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')
+    group by user_id
+) c
+                   on a.user_id = c.user_id
+         left join (
+    select user_id,
+           sum(cost) as quarter_cost
+    from application.app_bytedance_advertiser_report_busi_m
+    where stat_mon between case
+                               when quarter(date_sub(now(), interval 1 day)) = 1 then 202201
+                               when quarter(date_sub(now(), interval 1 day)) = 2 then 202204
+                               when quarter(date_sub(now(), interval 1 day)) = 3 then 202207
+                               when quarter(date_sub(now(), interval 1 day)) = 4 then 202210
+        end
+              and
+              case
+                  when quarter(date_sub(now(), interval 1 day)) = 1 then 202203
+                  when quarter(date_sub(now(), interval 1 day)) = 2 then 202206
+                  when quarter(date_sub(now(), interval 1 day)) = 3 then 202209
+                  when quarter(date_sub(now(), interval 1 day)) = 4 then 202212
+                  end
+    group by user_id
+) d
+                   on a.user_id = d.user_id
+left join `jeecg-boot`.sys_user user
+on a.user_id=user.id
+
+
+-- 项目
+
+select :date                                                                as date,
+       project_name,
+       account_count,
+       user_count,
+       a.cost,
+       concat(round(ifnull((a.cost - c.cost) / (c.cost) * 100, 2), 0), '%') as cost_rate,
+       d.tb_rate,
+       e.hot_num
+
+from (select project_id, project_name, count(1) as account_count, sum(cost) as cost
+      from (
+               select project_id, project_name, account_id, sum(cost) as cost
+               from application.bytedance_advertiser_report_daily_dw
+               where stat_datetime between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')
+                 and cost > 0
+                 and company_id = 'd57fecdcf7a94d009736d9c850731582'
+                   and user_id in(
+        select id from `jeecg-boot`.sys_user where leader_id='c52551687c524a96a3904658a35f0f26'
+        union all
+        select id from `jeecg-boot`.sys_user where id='c52551687c524a96a3904658a35f0f26'
+          )
+               group by project_id, account_id) t
+      group by project_id) a
+         left join
+     (select project_id, count(1) as user_count
+      from (
+               select project_id, user_id
+               from `jeecg-boot`.ctop_user_allocation
+               group by project_id, user_id) t
+      group by project_id) b
+     on a.project_id = b.project_id
+         left join(
+    select project_id, sum(cost) as cost
+    from application.bytedance_advertiser_report_daily_dw
+    where stat_datetime between date_format(date_sub(:date, interval 13 day), '%Y%m%d') and date_format(date_sub(:date, interval 7 day), '%Y%m%d')
+      and cost > 0
+      and company_id = 'd57fecdcf7a94d009736d9c850731582'
+    group by project_id
+) c
+                  on a.project_id = c.project_id
+         left join (
+    select a.project_id, concat(round((sum(a.cost) - sum(b.cost)) / sum(b.cost) * 100, 2), '%') as tb_rate
+    from application.bytedance_advertiser_report_daily_dw a
+             left join application.bytedance_advertiser_report_daily_dw b
+                       on a.project_id = b.project_id
+    where a.stat_datetime = date_format(:date, '%Y%m%d')
+      and b.stat_datetime = date_format(date_sub(:date, interval 6 day), '%Y%m%d')
+    group by a.project_id,b.project_id
+) d
+                   on a.project_id = d.project_id
+         left join (
+    select project_id, sum(new_hot_num) as hot_num
+    from application.app_bytedance_account_base_info_d
+    where stat_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')
+    group by project_id
+) e
+                   on a.project_id = e.project_id
+
+
+
+-- 账户
+
+
+select :date as date,
+       account_name,
+       a.account_id,
+       realname,
+       cost,
+       c.cost_rate,
+       b.tb_rate
+from (select account_id, account_name, user_id, cost
+      from application.bytedance_advertiser_report_daily_dw
+      where stat_datetime = date_format(:date, '%Y%m%d')
+        and cost > 0
+        and company_id = 'd57fecdcf7a94d009736d9c850731582'
+        and user_id in(
+        select id from `jeecg-boot`.sys_user where leader_id='c52551687c524a96a3904658a35f0f26'
+        union all
+        select id from `jeecg-boot`.sys_user where id='c52551687c524a96a3904658a35f0f26'
+          )) a
+         left join (
+    select a.account_id, concat(round((a.cost - b.cost) / b.cost * 100, 2), '%') as tb_rate
+    from application.bytedance_advertiser_report_daily_dw a
+             left join application.bytedance_advertiser_report_daily_dw b
+                       on a.account_id = b.account_id
+    where a.stat_datetime = date_format(:date, '%Y%m%d')
+      and b.stat_datetime = date_format(date_sub(:date, interval 6 day), '%Y%m%d')
+) b
+                   on a.account_id = b.account_id
+         left join(
+    select t.account_id, concat(round((t.cost - t1.yes_week_cost) / t1.yes_week_cost * 100, 2), '%') as cost_rate
+    from (select account_id, sum(cost) as cost
+          from application.bytedance_advertiser_report_daily_dw
+          where stat_datetime between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')
+            and cost > 0
+          group by account_id) t
+             left join
+         (select account_id, sum(cost) as yes_week_cost
+          from application.bytedance_advertiser_report_daily_dw
+          where stat_datetime between date_format(date_sub(:date, interval 13 day), '%Y%m%d') and date_format(date_sub(:date, interval 7 day), '%Y%m%d')
+            and cost > 0
+          group by account_id) t1
+         on t.account_id = t1.account_id
+) c
+                  on a.account_id = c.account_id
+         left join `jeecg-boot`.sys_user user
+                   on a.user_id = user.id

+ 344 - 0
sql/头条编导排名.sql

@@ -0,0 +1,344 @@
+select
+       concat(date_format(date_sub(:date, interval 6 day), '%Y%m%d') ,'-',date_format(:date, '%Y%m%d')) as stat_datetime,
+       round(row_number() over (order by plan_cost desc ),0) as rn,
+       plan_name,
+       plan_cost,
+       ifnull(hot_num,0) as hot_num,
+       ifnull(hot_cost,0) as hot_cost,
+       concat(round(ifnull(hot_num/material_num*100,0),2),'%') as hot_rate,
+       ifnull(material_num,0) as material_num,
+       ifnull(plan_num,0) as plan_num,
+       ifnull(hotplancount,0) as  hotplancount,
+       ifnull(man_num,0) as man_num,
+       ifnull(hotmancount,0) as hotmancount,
+      concat(round(ifnull(plan_cost/sumcost*100,0),2),'%') as cost_rate
+
+from (
+         select plan_name,
+                sum(plan_cost) as plan_cost,
+                sumcost,
+                sum(hot_num)      as hot_num,
+                sum(material_num) as material_num,
+                sum(hot_cost)     as hot_cost,
+                sum(man_num)      as man_num,
+                sum(hotmancount)  as hotmancount,
+                sum(plan_num)     as plan_num,
+                sum(hotplancount) as hotplancount
+         from (
+                  select info.plan_id,
+                         case
+                             when info.plan_name like '%汇创%' then replace(plan_name, '(汇创)', '')
+                             else plan_name end as plan_name,
+                         info.plan_cost,
+                         info.sumcost,
+                         hot_num,
+                         hot_cost,
+                         material_num,
+                         man_num,
+                         hotmancount,
+                         plan_num,
+                         hotplancount
+                  from (select plan_id, plan_name, plan_cost, sumcost
+                        from (select plan_id, plan_name, sum(cost) as plan_cost
+                              from application.bytedance_material_video_report_daily_dw
+                              where stat_datetime between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')
+                                and clip_company_id in
+                                    ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                and plan_id is not null
+                              group by plan_id, plan_name) a
+                                 join (select sum(cost) as sumcost
+                                       from application.bytedance_material_video_report_daily_dw
+                                       where stat_datetime between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')
+                                         and clip_company_id in
+                                             ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                         and plan_id is not null) b) info
+
+
+                           left join (
+                      select plan_id, count(1) as material_num
+                      from `jeecg-boot`.ctop_material_ascription
+                      where create_time between date_format(date_sub(:date, interval 6 day), '%Y-%m-%d')
+                          and date_format(date_sub(:date, interval -1 day), '%Y-%m-%d')
+                        and plan_id in (select user_id
+                                          from `jeecg-boot`.user_company
+                                          where company_id in
+                                                ('d57fecdcf7a94d009736d9c850731582',
+                                                 '5e46b5dea3d740eeb8ff1a2895015a4b'))
+                      group by plan_id) b
+                                     on info.plan_id = b.plan_id
+                           left join(
+                      select plan_id, sum(hot_num) as hot_num, sum(hot_cost) as hot_cost
+                      from (
+                               select b.plan_id, count(1) as hot_num, sum(hot_cost) as hot_cost
+                               from (select signature
+                                     from application.hot_material
+                                     where media_id = 1
+                                       and hot_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')) a
+                                        inner join
+                                    (select material_id, plan_id
+                                     from `jeecg-boot`.ctop_material_ascription
+                                     where plan_id in (select user_id
+                                                         from `jeecg-boot`.user_company
+                                                         where company_id in
+                                                               ('d57fecdcf7a94d009736d9c850731582',
+                                                                '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                     )) b
+                                    on a.signature = b.material_id
+                                        left join(
+                                   select *
+                                   from application.hot_material_two_week_cost
+                                   where media_id = 1
+                               ) c
+                                                 on a.signature = c.signature
+                                        left join (select material_id, parent_id, parent_name
+                                                   from application.app_material_tag_busi_info
+                                                   where tag_category_id = 1
+                                                   group by material_id, parent_id) d
+                                                  on a.signature = d.material_id
+                               group by plan_id, a.signature) t
+                      group by plan_id) c
+                                    on info.plan_id = c.plan_id
+                           left join (
+                      select plan_id, parent_id, count(distinct tag.material_id) as man_num
+                      from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+
+                      where create_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d')
+                          and date_format(date_sub(:date, interval -1 day), '%Y%m%d')
+                        and tag_category_id = 1
+                        and parent_id = 60155
+                      group by plan_id, parent_id) d
+                                     on info.plan_id = d.plan_id
+                           left join
+                       (select plan_id, parent_id, count(distinct tag.material_id)  as plan_num
+                        from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+                        where create_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d')
+                            and date_format(date_sub(:date, interval -1 day), '%Y%m%d')
+                          and tag_category_id = 1
+                          and parent_id = 60156
+                        group by plan_id, parent_id) e
+                       on info.plan_id = e.plan_id
+
+                           left join
+                       (select plan_id, count(distinct signature) as hotmancount
+                        from (select signature
+                              from application.hot_material
+                              where media_id = 1
+                                and hot_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')) a
+                                 inner join
+                             (select plan_id, tag.material_id
+                              from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+                              where tag_category_id = 1
+                                and parent_id = 60155
+                                and plan_id in (select user_id
+                                                  from `jeecg-boot`.user_company
+                                                  where company_id in
+                                                        ('d57fecdcf7a94d009736d9c850731582',
+                                                         '5e46b5dea3d740eeb8ff1a2895015a4b'))) b
+                             on a.signature = b.material_id
+                        group by plan_id) f
+                       on info.plan_id = f.plan_id
+                           left join
+                       (select plan_id, count(distinct signature) as hotplancount
+                        from (select signature
+                              from application.hot_material
+                              where media_id = 1
+                                and hot_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')) a
+                                 inner join
+                             (select plan_id, tag.material_id
+                              from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+                              where tag_category_id = 1
+                                and parent_id = 60156
+                                and plan_id in (select user_id
+                                                  from `jeecg-boot`.user_company
+                                                  where company_id in
+                                                        ('d57fecdcf7a94d009736d9c850731582',
+                                                         '5e46b5dea3d740eeb8ff1a2895015a4b'))) b
+                             on a.signature = b.material_id
+                        group by plan_id) i
+                       on info.plan_id = i.plan_id) t
+         group by plan_name, sumcost) t;
+
+
+
+
+
+
+
+
+
+
+
+select
+       concat(date_format(date_sub(:date, interval 6 day), '%Y%m%d') ,'-',date_format(:date, '%Y%m%d')) as stat_datetime,
+       '' rn,
+      '汇总' plan_name,
+       sum(plan_cost) as plan_cost,
+       ifnull(sum(hot_num),0) as hot_num,
+       ifnull(sum(hot_cost),0) as hot_cost,
+       concat(round(ifnull(sum(hot_num)/sum(material_num)*100,0),2),'%') as hot_rate,
+       ifnull(sum(material_num),0) as material_num,
+       ifnull(sum(plan_num),0) as plan_num,
+       ifnull(sum(hotplancount),0) as  hotplancount,
+       ifnull(sum(man_num),0) as man_num,
+       ifnull(sum(hotmancount),0) as hotmancount,
+       '' as cost_rate
+from (
+         select plan_name,
+                sum(plan_cost) as plan_cost,
+                sumcost,
+                sum(hot_num)      as hot_num,
+                sum(material_num) as material_num,
+                sum(hot_cost)     as hot_cost,
+                sum(man_num)      as man_num,
+                sum(hotmancount)  as hotmancount,
+                sum(plan_num)     as plan_num,
+                sum(hotplancount) as hotplancount
+         from (
+                  select info.plan_id,
+                         case
+                             when info.plan_name like '%汇创%' then replace(plan_name, '(汇创)', '')
+                             else plan_name end as plan_name,
+                         info.plan_cost,
+                         info.sumcost,
+                         hot_num,
+                         hot_cost,
+                         material_num,
+                         man_num,
+                         hotmancount,
+                         plan_num,
+                         hotplancount
+                  from (select plan_id, plan_name, plan_cost, sumcost
+                        from (select plan_id, plan_name, sum(cost) as plan_cost
+                              from application.bytedance_material_video_report_daily_dw
+                              where stat_datetime between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')
+                                and clip_company_id in
+                                    ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                and plan_id is not null
+                              group by plan_id, plan_name) a
+                                 join (select sum(cost) as sumcost
+                                       from application.bytedance_material_video_report_daily_dw
+                                       where stat_datetime between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')
+                                         and clip_company_id in
+                                             ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                         and plan_id is not null) b) info
+
+
+                           left join (
+                      select plan_id, count(1) as material_num
+                      from `jeecg-boot`.ctop_material_ascription
+                      where create_time between date_format(date_sub(:date, interval 6 day), '%Y-%m-%d')
+                          and date_format(date_sub(:date, interval -1 day), '%Y-%m-%d')
+                        and plan_id in (select user_id
+                                          from `jeecg-boot`.user_company
+                                          where company_id in
+                                                ('d57fecdcf7a94d009736d9c850731582',
+                                                 '5e46b5dea3d740eeb8ff1a2895015a4b'))
+                      group by plan_id) b
+                                     on info.plan_id = b.plan_id
+                           left join(
+                      select plan_id, sum(hot_num) as hot_num, sum(hot_cost) as hot_cost
+                      from (
+                               select b.plan_id, count(1) as hot_num, sum(hot_cost) as hot_cost
+                               from (select signature
+                                     from application.hot_material
+                                     where media_id = 1
+                                       and hot_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')) a
+                                        inner join
+                                    (select material_id, plan_id
+                                     from `jeecg-boot`.ctop_material_ascription
+                                     where plan_id in (select user_id
+                                                         from `jeecg-boot`.user_company
+                                                         where company_id in
+                                                               ('d57fecdcf7a94d009736d9c850731582',
+                                                                '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                     )) b
+                                    on a.signature = b.material_id
+                                        left join(
+                                   select *
+                                   from application.hot_material_two_week_cost
+                                   where media_id = 1
+                               ) c
+                                                 on a.signature = c.signature
+                                        left join (select material_id, parent_id, parent_name
+                                                   from application.app_material_tag_busi_info
+                                                   where tag_category_id = 1
+                                                   group by material_id, parent_id) d
+                                                  on a.signature = d.material_id
+                               group by plan_id, a.signature) t
+                      group by plan_id) c
+                                    on info.plan_id = c.plan_id
+                           left join (
+                      select plan_id, parent_id, count(distinct tag.material_id) as man_num
+                      from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+
+                      where create_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d')
+                          and date_format(date_sub(:date, interval -1 day), '%Y%m%d')
+                        and tag_category_id = 1
+                        and parent_id = 60155
+                      group by plan_id, parent_id) d
+                                     on info.plan_id = d.plan_id
+                           left join
+                       (select plan_id, parent_id, count(distinct tag.material_id)  as plan_num
+                        from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+                        where create_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d')
+                            and date_format(date_sub(:date, interval -1 day), '%Y%m%d')
+                          and tag_category_id = 1
+                          and parent_id = 60156
+                        group by plan_id, parent_id) e
+                       on info.plan_id = e.plan_id
+
+                           left join
+                       (select plan_id, count(distinct signature) as hotmancount
+                        from (select signature
+                              from application.hot_material
+                              where media_id = 1
+                                and hot_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')) a
+                                 inner join
+                             (select plan_id, tag.material_id
+                              from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+                              where tag_category_id = 1
+                                and parent_id = 60155
+                                and plan_id in (select user_id
+                                                  from `jeecg-boot`.user_company
+                                                  where company_id in
+                                                        ('d57fecdcf7a94d009736d9c850731582',
+                                                         '5e46b5dea3d740eeb8ff1a2895015a4b'))) b
+                             on a.signature = b.material_id
+                        group by plan_id) f
+                       on info.plan_id = f.plan_id
+                           left join
+                       (select plan_id, count(distinct signature) as hotplancount
+                        from (select signature
+                              from application.hot_material
+                              where media_id = 1
+                                and hot_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')) a
+                                 inner join
+                             (select plan_id, tag.material_id
+                              from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+                              where tag_category_id = 1
+                                and parent_id = 60156
+                                and plan_id in (select user_id
+                                                  from `jeecg-boot`.user_company
+                                                  where company_id in
+                                                        ('d57fecdcf7a94d009736d9c850731582',
+                                                         '5e46b5dea3d740eeb8ff1a2895015a4b'))) b
+                             on a.signature = b.material_id
+                        group by plan_id) i
+                       on info.plan_id = i.plan_id) t
+         group by plan_name, sumcost) t

+ 320 - 0
sql/头条设计组长排名.sql

@@ -0,0 +1,320 @@
+-- 明细
+select
+
+       round(row_number() over (order by leadercost desc ),0) as rn,
+       leader_name,
+       leadercost,
+       ifnull(hot_num,0) as hot_num,
+       ifnull(hot_cost,0) as hot_cost,
+       concat(round(ifnull(hot_num/material_num*100,0),2),'%') as hot_rate,
+       ifnull(material_num,0) as material_num,
+       ifnull(material_num,0)  as  script_num,
+       ifnull(plan_num,0) as plan_num,
+       ifnull(hotplancount,0) as  hotplancount,
+       ifnull(man_num,0) as man_num,
+       ifnull(hotmancount,0) as hotmancount,
+       ifnull(plan_num,0) as script_plan_num,
+       ifnull(hotplancount,0) as  script_hotplancount,
+       ifnull(man_num,0) as script_man_num,
+       ifnull(hotmancount,0) as script_hotmancount,
+      concat(round(ifnull(leadercost/sumcost*100,0),2),'%') as cost_rate,
+       1 as sort
+from (
+         select leader_name,
+                sum(leadercost) as leadercost,
+                sumcost,
+                sum(hot_num)      as hot_num,
+                sum(material_num) as material_num,
+                sum(hot_cost)     as hot_cost,
+                sum(man_num)      as man_num,
+                sum(hotmancount)  as hotmancount,
+                sum(plan_num)     as plan_num,
+                sum(hotplancount) as hotplancount
+         from (
+                  select info.leader_id,
+                         case
+                             when info.leader_name like '%汇创%' then replace(leader_name, '(汇创)', '')
+                             else leader_name end as leader_name,
+                         info.leadercost,
+                         info.sumcost,
+                         hot_num,
+                         hot_cost,
+                         material_num,
+                         man_num,
+                         hotmancount,
+                         plan_num,
+                         hotplancount
+                  from (select leader_id, leader_name, leadercost, sumcost
+                        from (select leader_id, leader_name, sum(cost) as leadercost
+                              from application.bytedance_material_video_report_daily_dw
+                              where stat_datetime between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d') and date_format('2022-05-17', '%Y%m%d')
+                                and clip_company_id in
+                                    ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                and leader_id is not null
+                              group by leader_id, leader_name) a
+                                 join (select sum(cost) as sumcost
+                                       from application.bytedance_material_video_report_daily_dw
+                                       where stat_datetime between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d') and date_format('2022-05-17', '%Y%m%d')
+                                         and clip_company_id in
+                                             ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                         and leader_id is not null) b) info
+
+
+                           left join (
+                      select leader_id, count(1) as material_num
+                      from `jeecg-boot`.ctop_material_ascription
+                      where create_time between date_format(date_sub('2022-05-17', interval 6 day), '%Y-%m-%d')
+                          and date_format(date_sub('2022-05-17', interval -1 day), '%Y-%m-%d')
+                        and leader_id in (select user_id
+                                          from `jeecg-boot`.user_company
+                                          where company_id in
+                                                ('d57fecdcf7a94d009736d9c850731582',
+                                                 '5e46b5dea3d740eeb8ff1a2895015a4b'))
+                      group by leader_id) b
+                                     on info.leader_id = b.leader_id
+                           left join(
+                      select leader_id, sum(hot_num) as hot_num, sum(hot_cost) as hot_cost
+                      from (
+                               select b.leader_id, count(1) as hot_num, sum(hot_cost) as hot_cost
+                               from (select signature
+                                     from application.hot_material
+                                     where media_id = 1
+                                       and hot_date between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d') and date_format('2022-05-17', '%Y%m%d')) a
+                                        inner join
+                                    (select material_id, leader_id
+                                     from `jeecg-boot`.ctop_material_ascription
+                                     where leader_id in (select user_id
+                                                         from `jeecg-boot`.user_company
+                                                         where company_id in
+                                                               ('d57fecdcf7a94d009736d9c850731582',
+                                                                '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                     )) b
+                                    on a.signature = b.material_id
+                                        left join(
+                                   select *
+                                   from application.hot_material_two_week_cost
+                                   where media_id = 1
+                               ) c
+                                                 on a.signature = c.signature
+                                        left join (select material_id, parent_id, parent_name
+                                                   from application.app_material_tag_busi_info
+                                                   where tag_category_id = 1
+                                                   group by material_id, parent_id) d
+                                                  on a.signature = d.material_id
+                               group by leader_id, a.signature) t
+                      group by leader_id) c
+                                    on info.leader_id = c.leader_id
+                           left join (
+                      select leader_id, parent_id, count(distinct material_id) as man_num
+                      from application.app_material_tag_busi_info
+                      where create_date between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d')
+                          and date_format(date_sub('2022-05-17', interval -1 day), '%Y%m%d')
+                        and tag_category_id = 1
+                        and parent_id = 60155
+                      group by leader_id, parent_id) d
+                                     on info.leader_id = d.leader_id
+                           left join
+                       (select leader_id, parent_id, count(distinct material_id)  as plan_num
+                        from application.app_material_tag_busi_info
+                        where create_date between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d')
+                            and date_format(date_sub('2022-05-17', interval -1 day), '%Y%m%d')
+                          and tag_category_id = 1
+                          and parent_id = 60156
+                        group by leader_id, parent_id) e
+                       on info.leader_id = e.leader_id
+
+                           left join
+                       (select leader_id, count(distinct signature) as hotmancount
+                        from (select signature
+                              from application.hot_material
+                              where media_id = 1
+                                and hot_date between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d') and date_format('2022-05-17', '%Y%m%d')) a
+                                 inner join
+                             (select leader_id, material_id
+                              from application.app_material_tag_busi_info
+                              where tag_category_id = 1
+                                and parent_id = 60155
+                                and leader_id in (select user_id
+                                                  from `jeecg-boot`.user_company
+                                                  where company_id in
+                                                        ('d57fecdcf7a94d009736d9c850731582',
+                                                         '5e46b5dea3d740eeb8ff1a2895015a4b'))) b
+                             on a.signature = b.material_id
+                        group by leader_id) f
+                       on info.leader_id = f.leader_id
+                           left join
+                       (select leader_id, count(distinct signature) as hotplancount
+                        from (select signature
+                              from application.hot_material
+                              where media_id = 1
+                                and hot_date between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d') and date_format('2022-05-17', '%Y%m%d')) a
+                                 inner join
+                             (select leader_id, material_id
+                              from application.app_material_tag_busi_info
+                              where tag_category_id = 1
+                                and parent_id = 60156
+                                and leader_id in (select user_id
+                                                  from `jeecg-boot`.user_company
+                                                  where company_id in
+                                                        ('d57fecdcf7a94d009736d9c850731582',
+                                                         '5e46b5dea3d740eeb8ff1a2895015a4b'))) b
+                             on a.signature = b.material_id
+                        group by leader_id) i
+                       on info.leader_id = i.leader_id) t
+         group by leader_name, sumcost) t;
+
+-- 汇总
+
+select
+       '' as rn,
+       '汇总' leader_name,
+       sum(leadercost) as leadercost,
+       ifnull(sum(hot_num),0) as hot_num,
+       ifnull(sum(hot_cost),0) as hot_cost,
+       concat(round(ifnull(sum(hot_num)/sum(material_num)*100,0),2),'%') as hot_rate,
+       ifnull(sum(material_num),0) as material_num,
+       ifnull(sum(material_num),0)  as  script_num,
+       ifnull(sum(plan_num),0) as plan_num,
+       ifnull(sum(hotplancount),0) as  hotplancount,
+       ifnull(sum(man_num),0) as man_num,
+       ifnull(sum(hotmancount),0) as hotmancount,
+       ifnull(sum(plan_num),0) as script_plan_num,
+       ifnull(sum(hotplancount),0) as  script_hotplancount,
+       ifnull(sum(man_num),0) as script_man_num,
+       ifnull(sum(hotmancount),0) as script_hotmancount,
+       '' as cost_rate
+from (
+         select leader_name,
+                sum(leadercost) as leadercost,
+                sum(hot_num)      as hot_num,
+                sum(material_num) as material_num,
+                sum(hot_cost)     as hot_cost,
+                sum(man_num)      as man_num,
+                sum(hotmancount)  as hotmancount,
+                sum(plan_num)     as plan_num,
+                sum(hotplancount) as hotplancount
+         from (
+                  select info.leader_id,
+                         case
+                             when info.leader_name like '%汇创%' then replace(leader_name, '(汇创)', '')
+                             else leader_name end as leader_name,
+                         info.leadercost,
+                         hot_num,
+                         hot_cost,
+                         material_num,
+                         man_num,
+                         hotmancount,
+                         plan_num,
+                         hotplancount
+                  from (select leader_id, leader_name, leadercost
+                        from (select leader_id, leader_name, sum(cost) as leadercost
+                              from application.bytedance_material_video_report_daily_dw
+                              where stat_datetime between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d') and date_format('2022-05-17', '%Y%m%d')
+                                and clip_company_id in
+                                    ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                and leader_id is not null
+                              group by leader_id, leader_name) a) info
+
+
+                           left join (
+                      select leader_id, count(1) as material_num
+                      from `jeecg-boot`.ctop_material_ascription
+                      where create_time between date_format(date_sub('2022-05-17', interval 6 day), '%Y-%m-%d')
+                          and date_format(date_sub('2022-05-17', interval -1 day), '%Y-%m-%d')
+                        and leader_id in (select user_id
+                                          from `jeecg-boot`.user_company
+                                          where company_id in
+                                                ('d57fecdcf7a94d009736d9c850731582',
+                                                 '5e46b5dea3d740eeb8ff1a2895015a4b'))
+                      group by leader_id) b
+                                     on info.leader_id = b.leader_id
+                           left join(
+                      select leader_id, sum(hot_num) as hot_num, sum(hot_cost) as hot_cost
+                      from (
+                               select b.leader_id, count(1) as hot_num, sum(hot_cost) as hot_cost
+                               from (select signature
+                                     from application.hot_material
+                                     where media_id = 1
+                                       and hot_date between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d') and date_format('2022-05-17', '%Y%m%d')) a
+                                        inner join
+                                    (select material_id, leader_id
+                                     from `jeecg-boot`.ctop_material_ascription
+                                     where leader_id in (select user_id
+                                                         from `jeecg-boot`.user_company
+                                                         where company_id in
+                                                               ('d57fecdcf7a94d009736d9c850731582',
+                                                                '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                     )) b
+                                    on a.signature = b.material_id
+                                        left join(
+                                   select *
+                                   from application.hot_material_two_week_cost
+                                   where media_id = 1
+                               ) c
+                                                 on a.signature = c.signature
+                                        left join (select material_id, parent_id, parent_name
+                                                   from application.app_material_tag_busi_info
+                                                   where tag_category_id = 1
+                                                   group by material_id, parent_id) d
+                                                  on a.signature = d.material_id
+                               group by leader_id, a.signature) t
+                      group by leader_id) c
+                                    on info.leader_id = c.leader_id
+                           left join (
+                      select leader_id, parent_id, count(distinct material_id) as man_num
+                      from application.app_material_tag_busi_info
+                      where create_date between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d')
+                          and date_format(date_sub('2022-05-17', interval -1 day), '%Y%m%d')
+                        and tag_category_id = 1
+                        and parent_id = 60155
+                      group by leader_id, parent_id) d
+                                     on info.leader_id = d.leader_id
+                           left join
+                       (select leader_id, parent_id, count(distinct material_id)  as plan_num
+                        from application.app_material_tag_busi_info
+                        where create_date between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d')
+                            and date_format(date_sub('2022-05-17', interval -1 day), '%Y%m%d')
+                          and tag_category_id = 1
+                          and parent_id = 60156
+                        group by leader_id, parent_id) e
+                       on info.leader_id = e.leader_id
+
+                           left join
+                       (select leader_id, count(distinct signature) as hotmancount
+                        from (select signature
+                              from application.hot_material
+                              where media_id = 1
+                                and hot_date between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d') and date_format('2022-05-17', '%Y%m%d')) a
+                                 inner join
+                             (select leader_id, material_id
+                              from application.app_material_tag_busi_info
+                              where tag_category_id = 1
+                                and parent_id = 60155
+                                and leader_id in (select user_id
+                                                  from `jeecg-boot`.user_company
+                                                  where company_id in
+                                                        ('d57fecdcf7a94d009736d9c850731582',
+                                                         '5e46b5dea3d740eeb8ff1a2895015a4b'))) b
+                             on a.signature = b.material_id
+                        group by leader_id) f
+                       on info.leader_id = f.leader_id
+                           left join
+                       (select leader_id, count(distinct signature) as hotplancount
+                        from (select signature
+                              from application.hot_material
+                              where media_id = 1
+                                and hot_date between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d') and date_format('2022-05-17', '%Y%m%d')) a
+                                 inner join
+                             (select leader_id, material_id
+                              from application.app_material_tag_busi_info
+                              where tag_category_id = 1
+                                and parent_id = 60156
+                                and leader_id in (select user_id
+                                                  from `jeecg-boot`.user_company
+                                                  where company_id in
+                                                        ('d57fecdcf7a94d009736d9c850731582',
+                                                         '5e46b5dea3d740eeb8ff1a2895015a4b'))) b
+                             on a.signature = b.material_id
+                        group by leader_id) i
+                       on info.leader_id = i.leader_id) t
+         group by leader_name) t

+ 33 - 0
sql/对比消耗.sql

@@ -0,0 +1,33 @@
+select project_name,thrteenday.signature,thrteenday.video_name,photo_url, sum30charge, sum3charge
+from (select a.signature, video_name, round(sum(charge), 2) as sum30charge,photo_url,project_name
+      from (select signature, frast_cost_time
+            from application.material_farst_cost_time
+            where frast_cost_time >= date_format(date_sub(20220706, interval 30 day), '%Y%m%d')
+           and frast_cost_time<=date_format(date_sub(20220706, interval 3 day), '%Y%m%d')) a
+               left join(
+          select stat_date, signature, video_name,photo_url,project_name, sum(charge) as charge
+          from application.kuaishou_material_video_report_daily_dw
+          where stat_date >= date_format(date_sub(20220706, interval 30 day), '%Y%m%d')
+          group by signature, video_name, stat_date
+      ) b
+                        on a.signature = b.signature
+      where stat_date between  frast_cost_time and date_format(date_sub(frast_cost_time, interval -30 day), '%Y%m%d')
+      group by a.signature) thrteenday
+         left join(
+    select a.signature, video_name, round(sum(charge), 2) as sum3charge
+    from (select signature, frast_cost_time
+          from application.material_farst_cost_time
+          where frast_cost_time >= date_format(date_sub(20220706, interval 30 day), '%Y%m%d')
+        and frast_cost_time<=date_format(date_sub(20220706, interval 3 day), '%Y%m%d')) a
+             left join(
+        select stat_date, signature, video_name, sum(charge) as charge
+        from application.kuaishou_material_video_report_daily_dw
+        where stat_date >= date_format(date_sub(20220706, interval 30 day), '%Y%m%d')
+        group by signature, video_name, stat_date
+    ) b
+                      on a.signature = b.signature
+    where stat_date between  frast_cost_time and date_format(date_sub(frast_cost_time, interval -3 day), '%Y%m%d')
+    group by a.signature
+) thrnday
+                  on thrteenday.signature = thrnday.signature
+where sum30charge = sum3charge

+ 341 - 0
sql/快手剪辑排名.sql

@@ -0,0 +1,341 @@
+select
+       concat(date_format(date_sub(:date, interval 6 day), '%Y%m%d') ,'-',date_format(:date, '%Y%m%d')) as stat_date,
+       round(row_number() over (order by clip_charge desc ),0) as rn,
+       clip_name,
+       clip_charge,
+       ifnull(hot_num,0) as hot_num,
+       ifnull(hot_cost,0) as hot_cost,
+       concat(round(ifnull(hot_num/material_num*100,0),2),'%') as hot_rate,
+       ifnull(material_num,0) as material_num,
+       ifnull(plan_num,0) as plan_num,
+       ifnull(hotplancount,0) as  hotplancount,
+       ifnull(man_num,0) as man_num,
+       ifnull(hotmancount,0) as hotmancount
+from (
+         select clip_name,
+                sum(clip_charge) as clip_charge,
+                sumcharge,
+                sum(hot_num)      as hot_num,
+                sum(material_num) as material_num,
+                sum(hot_cost)     as hot_cost,
+                sum(man_num)      as man_num,
+                sum(hotmancount)  as hotmancount,
+                sum(plan_num)     as plan_num,
+                sum(hotplancount) as hotplancount
+         from (
+                  select info.clip_id,
+                         case
+                             when info.clip_name like '%汇创%' then replace(clip_name, '(汇创)', '')
+                             else clip_name end as clip_name,
+                         info.clip_charge,
+                         info.sumcharge,
+                         hot_num,
+                         hot_cost,
+                         material_num,
+                         man_num,
+                         hotmancount,
+                         plan_num,
+                         hotplancount
+                  from (select clip_id, clip_name, clip_charge, sumcharge
+                        from (select clip_id, clip_name, sum(charge) as clip_charge
+                              from application.kuaishou_material_video_report_daily_dw
+                              where stat_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')
+                                and clip_company_id in
+                                    ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                and clip_id is not null
+                              group by clip_id, clip_name) a
+                                 join (select sum(charge) as sumcharge
+                                       from application.kuaishou_material_video_report_daily_dw
+                                       where stat_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')
+                                         and clip_company_id in
+                                             ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                         and clip_id is not null) b) info
+
+
+                           left join (
+                      select clip_id, count(1) as material_num
+                      from `jeecg-boot`.ctop_material_ascription
+                      where create_time between date_format(date_sub(:date, interval 6 day), '%Y-%m-%d')
+                          and date_format(date_sub(:date, interval -1 day), '%Y-%m-%d')
+                        and clip_id in (select user_id
+                                          from `jeecg-boot`.user_company
+                                          where company_id in
+                                                ('d57fecdcf7a94d009736d9c850731582',
+                                                 '5e46b5dea3d740eeb8ff1a2895015a4b'))
+                      group by clip_id) b
+                                     on info.clip_id = b.clip_id
+                           left join(
+                      select clip_id, sum(hot_num) as hot_num, sum(hot_cost) as hot_cost
+                      from (
+                               select b.clip_id, count(1) as hot_num, sum(hot_cost) as hot_cost
+                               from (select signature
+                                     from application.hot_material
+                                     where media_id = 2
+                                       and hot_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')) a
+                                        inner join
+                                    (select material_id, clip_id
+                                     from `jeecg-boot`.ctop_material_ascription
+                                     where clip_id in (select user_id
+                                                         from `jeecg-boot`.user_company
+                                                         where company_id in
+                                                               ('d57fecdcf7a94d009736d9c850731582',
+                                                                '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                     )) b
+                                    on a.signature = b.material_id
+                                        left join(
+                                   select *
+                                   from application.hot_material_two_week_cost
+                                   where media_id = 2
+                               ) c
+                                                 on a.signature = c.signature
+                                        left join (select material_id, parent_id, parent_name
+                                                   from application.app_material_tag_busi_info
+                                                   where tag_category_id = 1
+                                                   group by material_id, parent_id) d
+                                                  on a.signature = d.material_id
+                               group by clip_id, a.signature) t
+                      group by clip_id) c
+                                    on info.clip_id = c.clip_id
+                           left join (
+                      select clip_id, parent_id, count(distinct tag.material_id) as man_num
+                      from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+
+                      where create_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d')
+                          and date_format(date_sub(:date, interval -1 day), '%Y%m%d')
+                        and tag_category_id = 1
+                        and parent_id = 60155
+                      group by clip_id, parent_id) d
+                                     on info.clip_id = d.clip_id
+                           left join
+                       (select clip_id, parent_id, count(distinct tag.material_id)  as plan_num
+                        from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+                        where create_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d')
+                            and date_format(date_sub(:date, interval -1 day), '%Y%m%d')
+                          and tag_category_id = 1
+                          and parent_id = 60156
+                        group by clip_id, parent_id) e
+                       on info.clip_id = e.clip_id
+
+                           left join
+                       (select clip_id, count(distinct signature) as hotmancount
+                        from (select signature
+                              from application.hot_material
+                              where media_id = 2
+                                and hot_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')) a
+                                 inner join
+                             (select clip_id, tag.material_id
+                              from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+                              where tag_category_id = 1
+                                and parent_id = 60155
+                                and clip_id in (select user_id
+                                                  from `jeecg-boot`.user_company
+                                                  where company_id in
+                                                        ('d57fecdcf7a94d009736d9c850731582',
+                                                         '5e46b5dea3d740eeb8ff1a2895015a4b'))) b
+                             on a.signature = b.material_id
+                        group by clip_id) f
+                       on info.clip_id = f.clip_id
+                           left join
+                       (select clip_id, count(distinct signature) as hotplancount
+                        from (select signature
+                              from application.hot_material
+                              where media_id = 2
+                                and hot_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')) a
+                                 inner join
+                             (select clip_id, tag.material_id
+                              from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+                              where tag_category_id = 1
+                                and parent_id = 60156
+                                and clip_id in (select user_id
+                                                  from `jeecg-boot`.user_company
+                                                  where company_id in
+                                                        ('d57fecdcf7a94d009736d9c850731582',
+                                                         '5e46b5dea3d740eeb8ff1a2895015a4b'))) b
+                             on a.signature = b.material_id
+                        group by clip_id) i
+                       on info.clip_id = i.clip_id) t
+         group by clip_name, sumcharge) t
+
+
+
+
+
+
+
+
+
+
+
+select
+       concat(date_format(date_sub(:date, interval 6 day), '%Y%m%d') ,'-',date_format(:date, '%Y%m%d')) as stat_date,
+       '' rn,
+      '汇总' clip_name,
+       sum(clip_charge) as clip_charge,
+       ifnull(sum(hot_num),0) as hot_num,
+       ifnull(sum(hot_cost),0) as hot_cost,
+       concat(round(ifnull(sum(hot_num)/sum(material_num)*100,0),2),'%') as hot_rate,
+       ifnull(sum(material_num),0) as material_num,
+       ifnull(sum(plan_num),0) as plan_num,
+       ifnull(sum(hotplancount),0) as  hotplancount,
+       ifnull(sum(man_num),0) as man_num,
+       ifnull(sum(hotmancount),0) as hotmancount
+from (
+         select clip_name,
+                sum(clip_charge) as clip_charge,
+                sumcharge,
+                sum(hot_num)      as hot_num,
+                sum(material_num) as material_num,
+                sum(hot_cost)     as hot_cost,
+                sum(man_num)      as man_num,
+                sum(hotmancount)  as hotmancount,
+                sum(plan_num)     as plan_num,
+                sum(hotplancount) as hotplancount
+         from (
+                  select info.clip_id,
+                         case
+                             when info.clip_name like '%汇创%' then replace(clip_name, '(汇创)', '')
+                             else clip_name end as clip_name,
+                         info.clip_charge,
+                         info.sumcharge,
+                         hot_num,
+                         hot_cost,
+                         material_num,
+                         man_num,
+                         hotmancount,
+                         plan_num,
+                         hotplancount
+                  from (select clip_id, clip_name, clip_charge, sumcharge
+                        from (select clip_id, clip_name, sum(charge) as clip_charge
+                              from application.kuaishou_material_video_report_daily_dw
+                              where stat_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')
+                                and clip_company_id in
+                                    ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                and clip_id is not null
+                              group by clip_id, clip_name) a
+                                 join (select sum(charge) as sumcharge
+                                       from application.kuaishou_material_video_report_daily_dw
+                                       where stat_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')
+                                         and clip_company_id in
+                                             ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                         and clip_id is not null) b) info
+
+
+                           left join (
+                      select clip_id, count(1) as material_num
+                      from `jeecg-boot`.ctop_material_ascription
+                      where create_time between date_format(date_sub(:date, interval 6 day), '%Y-%m-%d')
+                          and date_format(date_sub(:date, interval -1 day), '%Y-%m-%d')
+                        and clip_id in (select user_id
+                                          from `jeecg-boot`.user_company
+                                          where company_id in
+                                                ('d57fecdcf7a94d009736d9c850731582',
+                                                 '5e46b5dea3d740eeb8ff1a2895015a4b'))
+                      group by clip_id) b
+                                     on info.clip_id = b.clip_id
+                           left join(
+                      select clip_id, sum(hot_num) as hot_num, sum(hot_cost) as hot_cost
+                      from (
+                               select b.clip_id, count(1) as hot_num, sum(hot_cost) as hot_cost
+                               from (select signature
+                                     from application.hot_material
+                                     where media_id = 2
+                                       and hot_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')) a
+                                        inner join
+                                    (select material_id, clip_id
+                                     from `jeecg-boot`.ctop_material_ascription
+                                     where clip_id in (select user_id
+                                                         from `jeecg-boot`.user_company
+                                                         where company_id in
+                                                               ('d57fecdcf7a94d009736d9c850731582',
+                                                                '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                     )) b
+                                    on a.signature = b.material_id
+                                        left join(
+                                   select *
+                                   from application.hot_material_two_week_cost
+                                   where media_id = 2
+                               ) c
+                                                 on a.signature = c.signature
+                                        left join (select material_id, parent_id, parent_name
+                                                   from application.app_material_tag_busi_info
+                                                   where tag_category_id = 1
+                                                   group by material_id, parent_id) d
+                                                  on a.signature = d.material_id
+                               group by clip_id, a.signature) t
+                      group by clip_id) c
+                                    on info.clip_id = c.clip_id
+                           left join (
+                      select clip_id, parent_id, count(distinct tag.material_id) as man_num
+                      from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+
+                      where create_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d')
+                          and date_format(date_sub(:date, interval -1 day), '%Y%m%d')
+                        and tag_category_id = 1
+                        and parent_id = 60155
+                      group by clip_id, parent_id) d
+                                     on info.clip_id = d.clip_id
+                           left join
+                       (select clip_id, parent_id, count(distinct tag.material_id)  as plan_num
+                        from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+                        where create_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d')
+                            and date_format(date_sub(:date, interval -1 day), '%Y%m%d')
+                          and tag_category_id = 1
+                          and parent_id = 60156
+                        group by clip_id, parent_id) e
+                       on info.clip_id = e.clip_id
+
+                           left join
+                       (select clip_id, count(distinct signature) as hotmancount
+                        from (select signature
+                              from application.hot_material
+                              where media_id = 2
+                                and hot_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')) a
+                                 inner join
+                             (select clip_id, tag.material_id
+                              from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+                              where tag_category_id = 1
+                                and parent_id = 60155
+                                and clip_id in (select user_id
+                                                  from `jeecg-boot`.user_company
+                                                  where company_id in
+                                                        ('d57fecdcf7a94d009736d9c850731582',
+                                                         '5e46b5dea3d740eeb8ff1a2895015a4b'))) b
+                             on a.signature = b.material_id
+                        group by clip_id) f
+                       on info.clip_id = f.clip_id
+                           left join
+                       (select clip_id, count(distinct signature) as hotplancount
+                        from (select signature
+                              from application.hot_material
+                              where media_id = 2
+                                and hot_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')) a
+                                 inner join
+                             (select clip_id, tag.material_id
+                              from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+                              where tag_category_id = 1
+                                and parent_id = 60156
+                                and clip_id in (select user_id
+                                                  from `jeecg-boot`.user_company
+                                                  where company_id in
+                                                        ('d57fecdcf7a94d009736d9c850731582',
+                                                         '5e46b5dea3d740eeb8ff1a2895015a4b'))) b
+                             on a.signature = b.material_id
+                        group by clip_id) i
+                       on info.clip_id = i.clip_id) t
+         group by clip_name, sumcharge) t

+ 344 - 0
sql/快手编导排名.sql

@@ -0,0 +1,344 @@
+select
+       concat(date_format(date_sub(:date, interval 6 day), '%Y%m%d') ,'-',date_format(:date, '%Y%m%d')) as stat_date,
+       round(row_number() over (order by plan_charge desc ),0) as rn,
+       plan_name,
+       plan_charge,
+       ifnull(hot_num,0) as hot_num,
+       ifnull(hot_cost,0) as hot_cost,
+       concat(round(ifnull(hot_num/material_num*100,0),2),'%') as hot_rate,
+       ifnull(material_num,0) as material_num,
+       ifnull(plan_num,0) as plan_num,
+       ifnull(hotplancount,0) as  hotplancount,
+       ifnull(man_num,0) as man_num,
+       ifnull(hotmancount,0) as hotmancount,
+      concat(round(ifnull(plan_charge/sumcharge*100,0),2),'%') as cost_rate
+
+from (
+         select plan_name,
+                sum(plan_charge) as plan_charge,
+                sumcharge,
+                sum(hot_num)      as hot_num,
+                sum(material_num) as material_num,
+                sum(hot_cost)     as hot_cost,
+                sum(man_num)      as man_num,
+                sum(hotmancount)  as hotmancount,
+                sum(plan_num)     as plan_num,
+                sum(hotplancount) as hotplancount
+         from (
+                  select info.plan_id,
+                         case
+                             when info.plan_name like '%汇创%' then replace(plan_name, '(汇创)', '')
+                             else plan_name end as plan_name,
+                         info.plan_charge,
+                         info.sumcharge,
+                         hot_num,
+                         hot_cost,
+                         material_num,
+                         man_num,
+                         hotmancount,
+                         plan_num,
+                         hotplancount
+                  from (select plan_id, plan_name, plan_charge, sumcharge
+                        from (select plan_id, plan_name, sum(charge) as plan_charge
+                              from application.kuaishou_material_video_report_daily_dw
+                              where stat_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')
+                                and clip_company_id in
+                                    ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                and plan_id is not null
+                              group by plan_id, plan_name) a
+                                 join (select sum(charge) as sumcharge
+                                       from application.kuaishou_material_video_report_daily_dw
+                                       where stat_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')
+                                         and clip_company_id in
+                                             ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                         and plan_id is not null) b) info
+
+
+                           left join (
+                      select plan_id, count(1) as material_num
+                      from `jeecg-boot`.ctop_material_ascription
+                      where create_time between date_format(date_sub(:date, interval 6 day), '%Y-%m-%d')
+                          and date_format(date_sub(:date, interval -1 day), '%Y-%m-%d')
+                        and plan_id in (select user_id
+                                          from `jeecg-boot`.user_company
+                                          where company_id in
+                                                ('d57fecdcf7a94d009736d9c850731582',
+                                                 '5e46b5dea3d740eeb8ff1a2895015a4b'))
+                      group by plan_id) b
+                                     on info.plan_id = b.plan_id
+                           left join(
+                      select plan_id, sum(hot_num) as hot_num, sum(hot_cost) as hot_cost
+                      from (
+                               select b.plan_id, count(1) as hot_num, sum(hot_cost) as hot_cost
+                               from (select signature
+                                     from application.hot_material
+                                     where media_id = 2
+                                       and hot_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')) a
+                                        inner join
+                                    (select material_id, plan_id
+                                     from `jeecg-boot`.ctop_material_ascription
+                                     where plan_id in (select user_id
+                                                         from `jeecg-boot`.user_company
+                                                         where company_id in
+                                                               ('d57fecdcf7a94d009736d9c850731582',
+                                                                '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                     )) b
+                                    on a.signature = b.material_id
+                                        left join(
+                                   select *
+                                   from application.hot_material_two_week_cost
+                                   where media_id = 2
+                               ) c
+                                                 on a.signature = c.signature
+                                        left join (select material_id, parent_id, parent_name
+                                                   from application.app_material_tag_busi_info
+                                                   where tag_category_id = 1
+                                                   group by material_id, parent_id) d
+                                                  on a.signature = d.material_id
+                               group by plan_id, a.signature) t
+                      group by plan_id) c
+                                    on info.plan_id = c.plan_id
+                           left join (
+                      select plan_id, parent_id, count(distinct tag.material_id) as man_num
+                      from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+
+                      where create_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d')
+                          and date_format(date_sub(:date, interval -1 day), '%Y%m%d')
+                        and tag_category_id = 1
+                        and parent_id = 60155
+                      group by plan_id, parent_id) d
+                                     on info.plan_id = d.plan_id
+                           left join
+                       (select plan_id, parent_id, count(distinct tag.material_id)  as plan_num
+                        from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+                        where create_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d')
+                            and date_format(date_sub(:date, interval -1 day), '%Y%m%d')
+                          and tag_category_id = 1
+                          and parent_id = 60156
+                        group by plan_id, parent_id) e
+                       on info.plan_id = e.plan_id
+
+                           left join
+                       (select plan_id, count(distinct signature) as hotmancount
+                        from (select signature
+                              from application.hot_material
+                              where media_id = 2
+                                and hot_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')) a
+                                 inner join
+                             (select plan_id, tag.material_id
+                              from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+                              where tag_category_id = 1
+                                and parent_id = 60155
+                                and plan_id in (select user_id
+                                                  from `jeecg-boot`.user_company
+                                                  where company_id in
+                                                        ('d57fecdcf7a94d009736d9c850731582',
+                                                         '5e46b5dea3d740eeb8ff1a2895015a4b'))) b
+                             on a.signature = b.material_id
+                        group by plan_id) f
+                       on info.plan_id = f.plan_id
+                           left join
+                       (select plan_id, count(distinct signature) as hotplancount
+                        from (select signature
+                              from application.hot_material
+                              where media_id = 2
+                                and hot_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')) a
+                                 inner join
+                             (select plan_id, tag.material_id
+                              from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+                              where tag_category_id = 1
+                                and parent_id = 60156
+                                and plan_id in (select user_id
+                                                  from `jeecg-boot`.user_company
+                                                  where company_id in
+                                                        ('d57fecdcf7a94d009736d9c850731582',
+                                                         '5e46b5dea3d740eeb8ff1a2895015a4b'))) b
+                             on a.signature = b.material_id
+                        group by plan_id) i
+                       on info.plan_id = i.plan_id) t
+         group by plan_name, sumcharge) t;
+
+
+
+
+
+
+
+
+
+
+
+select
+       concat(date_format(date_sub(:date, interval 6 day), '%Y%m%d') ,'-',date_format(:date, '%Y%m%d')) as stat_date,
+       '' rn,
+      '汇总' plan_name,
+       sum(plan_charge) as plan_charge,
+       ifnull(sum(hot_num),0) as hot_num,
+       ifnull(sum(hot_cost),0) as hot_cost,
+       concat(round(ifnull(sum(hot_num)/sum(material_num)*100,0),2),'%') as hot_rate,
+       ifnull(sum(material_num),0) as material_num,
+       ifnull(sum(plan_num),0) as plan_num,
+       ifnull(sum(hotplancount),0) as  hotplancount,
+       ifnull(sum(man_num),0) as man_num,
+       ifnull(sum(hotmancount),0) as hotmancount,
+       '' as cost_rate
+from (
+         select plan_name,
+                sum(plan_charge) as plan_charge,
+                sumcharge,
+                sum(hot_num)      as hot_num,
+                sum(material_num) as material_num,
+                sum(hot_cost)     as hot_cost,
+                sum(man_num)      as man_num,
+                sum(hotmancount)  as hotmancount,
+                sum(plan_num)     as plan_num,
+                sum(hotplancount) as hotplancount
+         from (
+                  select info.plan_id,
+                         case
+                             when info.plan_name like '%汇创%' then replace(plan_name, '(汇创)', '')
+                             else plan_name end as plan_name,
+                         info.plan_charge,
+                         info.sumcharge,
+                         hot_num,
+                         hot_cost,
+                         material_num,
+                         man_num,
+                         hotmancount,
+                         plan_num,
+                         hotplancount
+                  from (select plan_id, plan_name, plan_charge, sumcharge
+                        from (select plan_id, plan_name, sum(charge) as plan_charge
+                              from application.kuaishou_material_video_report_daily_dw
+                              where stat_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')
+                                and clip_company_id in
+                                    ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                and plan_id is not null
+                              group by plan_id, plan_name) a
+                                 join (select sum(charge) as sumcharge
+                                       from application.kuaishou_material_video_report_daily_dw
+                                       where stat_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')
+                                         and clip_company_id in
+                                             ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                         and plan_id is not null) b) info
+
+
+                           left join (
+                      select plan_id, count(1) as material_num
+                      from `jeecg-boot`.ctop_material_ascription
+                      where create_time between date_format(date_sub(:date, interval 6 day), '%Y-%m-%d')
+                          and date_format(date_sub(:date, interval -1 day), '%Y-%m-%d')
+                        and plan_id in (select user_id
+                                          from `jeecg-boot`.user_company
+                                          where company_id in
+                                                ('d57fecdcf7a94d009736d9c850731582',
+                                                 '5e46b5dea3d740eeb8ff1a2895015a4b'))
+                      group by plan_id) b
+                                     on info.plan_id = b.plan_id
+                           left join(
+                      select plan_id, sum(hot_num) as hot_num, sum(hot_cost) as hot_cost
+                      from (
+                               select b.plan_id, count(1) as hot_num, sum(hot_cost) as hot_cost
+                               from (select signature
+                                     from application.hot_material
+                                     where media_id = 2
+                                       and hot_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')) a
+                                        inner join
+                                    (select material_id, plan_id
+                                     from `jeecg-boot`.ctop_material_ascription
+                                     where plan_id in (select user_id
+                                                         from `jeecg-boot`.user_company
+                                                         where company_id in
+                                                               ('d57fecdcf7a94d009736d9c850731582',
+                                                                '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                     )) b
+                                    on a.signature = b.material_id
+                                        left join(
+                                   select *
+                                   from application.hot_material_two_week_cost
+                                   where media_id = 2
+                               ) c
+                                                 on a.signature = c.signature
+                                        left join (select material_id, parent_id, parent_name
+                                                   from application.app_material_tag_busi_info
+                                                   where tag_category_id = 1
+                                                   group by material_id, parent_id) d
+                                                  on a.signature = d.material_id
+                               group by plan_id, a.signature) t
+                      group by plan_id) c
+                                    on info.plan_id = c.plan_id
+                           left join (
+                      select plan_id, parent_id, count(distinct tag.material_id) as man_num
+                      from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+
+                      where create_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d')
+                          and date_format(date_sub(:date, interval -1 day), '%Y%m%d')
+                        and tag_category_id = 1
+                        and parent_id = 60155
+                      group by plan_id, parent_id) d
+                                     on info.plan_id = d.plan_id
+                           left join
+                       (select plan_id, parent_id, count(distinct tag.material_id)  as plan_num
+                        from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+                        where create_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d')
+                            and date_format(date_sub(:date, interval -1 day), '%Y%m%d')
+                          and tag_category_id = 1
+                          and parent_id = 60156
+                        group by plan_id, parent_id) e
+                       on info.plan_id = e.plan_id
+
+                           left join
+                       (select plan_id, count(distinct signature) as hotmancount
+                        from (select signature
+                              from application.hot_material
+                              where media_id = 2
+                                and hot_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')) a
+                                 inner join
+                             (select plan_id, tag.material_id
+                              from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+                              where tag_category_id = 1
+                                and parent_id = 60155
+                                and plan_id in (select user_id
+                                                  from `jeecg-boot`.user_company
+                                                  where company_id in
+                                                        ('d57fecdcf7a94d009736d9c850731582',
+                                                         '5e46b5dea3d740eeb8ff1a2895015a4b'))) b
+                             on a.signature = b.material_id
+                        group by plan_id) f
+                       on info.plan_id = f.plan_id
+                           left join
+                       (select plan_id, count(distinct signature) as hotplancount
+                        from (select signature
+                              from application.hot_material
+                              where media_id = 2
+                                and hot_date between date_format(date_sub(:date, interval 6 day), '%Y%m%d') and date_format(:date, '%Y%m%d')) a
+                                 inner join
+                             (select plan_id, tag.material_id
+                              from application.app_material_tag_busi_info tag
+                       left join `jeecg-boot`.ctop_material_ascription info
+                       on tag.material_id=info.material_id
+                              where tag_category_id = 1
+                                and parent_id = 60156
+                                and plan_id in (select user_id
+                                                  from `jeecg-boot`.user_company
+                                                  where company_id in
+                                                        ('d57fecdcf7a94d009736d9c850731582',
+                                                         '5e46b5dea3d740eeb8ff1a2895015a4b'))) b
+                             on a.signature = b.material_id
+                        group by plan_id) i
+                       on info.plan_id = i.plan_id) t
+         group by plan_name, sumcharge) t

+ 320 - 0
sql/快手设计组长排名.sql

@@ -0,0 +1,320 @@
+-- 明细
+select
+
+       round(row_number() over (order by leadercharge desc ),0) as rn,
+       leader_name,
+       leadercharge,
+       ifnull(hot_num,0) as hot_num,
+       ifnull(hot_cost,0) as hot_cost,
+       concat(round(ifnull(hot_num/material_num*100,0),2),'%') as hot_rate,
+       ifnull(material_num,0) as material_num,
+       ifnull(material_num,0)  as  script_num,
+       ifnull(plan_num,0) as plan_num,
+       ifnull(hotplancount,0) as  hotplancount,
+       ifnull(man_num,0) as man_num,
+       ifnull(hotmancount,0) as hotmancount,
+       ifnull(plan_num,0) as script_plan_num,
+       ifnull(hotplancount,0) as  script_hotplancount,
+       ifnull(man_num,0) as script_man_num,
+       ifnull(hotmancount,0) as script_hotmancount,
+      concat(round(ifnull(leadercharge/sumcharge*100,0),2),'%') as charge_rate,
+       1 as sort
+from (
+         select leader_name,
+                sum(leadercharge) as leadercharge,
+                sumcharge,
+                sum(hot_num)      as hot_num,
+                sum(material_num) as material_num,
+                sum(hot_cost)     as hot_cost,
+                sum(man_num)      as man_num,
+                sum(hotmancount)  as hotmancount,
+                sum(plan_num)     as plan_num,
+                sum(hotplancount) as hotplancount
+         from (
+                  select info.leader_id,
+                         case
+                             when info.leader_name like '%汇创%' then replace(leader_name, '(汇创)', '')
+                             else leader_name end as leader_name,
+                         info.leadercharge,
+                         info.sumcharge,
+                         hot_num,
+                         hot_cost,
+                         material_num,
+                         man_num,
+                         hotmancount,
+                         plan_num,
+                         hotplancount
+                  from (select leader_id, leader_name, leadercharge, sumcharge
+                        from (select leader_id, leader_name, sum(charge) as leadercharge
+                              from application.kuaishou_material_video_report_daily_dw
+                              where stat_date between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d') and date_format('2022-5-17', '%Y%m%d')
+                                and clip_company_id in
+                                    ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                and leader_id is not null
+                              group by leader_id, leader_name) a
+                                 join (select sum(charge) as sumcharge
+                                       from application.kuaishou_material_video_report_daily_dw
+                                       where stat_date between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d') and date_format('2022-5-17', '%Y%m%d')
+                                         and clip_company_id in
+                                             ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                         and leader_id is not null) b) info
+
+
+                           left join (
+                      select leader_id, count(1) as material_num
+                      from `jeecg-boot`.ctop_material_ascription
+                      where create_time between date_format(date_sub('2022-05-17', interval 6 day), '%Y-%m-%d')
+                          and date_format(date_sub('2022-05-17', interval -1 day), '%Y-%m-%d')
+                        and leader_id in (select user_id
+                                          from `jeecg-boot`.user_company
+                                          where company_id in
+                                                ('d57fecdcf7a94d009736d9c850731582',
+                                                 '5e46b5dea3d740eeb8ff1a2895015a4b'))
+                      group by leader_id) b
+                                     on info.leader_id = b.leader_id
+                           left join(
+                      select leader_id, sum(hot_num) as hot_num, sum(hot_cost) as hot_cost
+                      from (
+                               select b.leader_id, count(1) as hot_num, sum(hot_cost) as hot_cost
+                               from (select signature
+                                     from application.hot_material
+                                     where media_id = 2
+                                       and hot_date between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d') and date_format('2022-5-17', '%Y%m%d')) a
+                                        inner join
+                                    (select material_id, leader_id
+                                     from `jeecg-boot`.ctop_material_ascription
+                                     where leader_id in (select user_id
+                                                         from `jeecg-boot`.user_company
+                                                         where company_id in
+                                                               ('d57fecdcf7a94d009736d9c850731582',
+                                                                '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                     )) b
+                                    on a.signature = b.material_id
+                                        left join(
+                                   select *
+                                   from application.hot_material_two_week_cost
+                                   where media_id = 2
+                               ) c
+                                                 on a.signature = c.signature
+                                        left join (select material_id, parent_id, parent_name
+                                                   from application.app_material_tag_busi_info
+                                                   where tag_category_id = 1
+                                                   group by material_id, parent_id) d
+                                                  on a.signature = d.material_id
+                               group by leader_id, a.signature) t
+                      group by leader_id) c
+                                    on info.leader_id = c.leader_id
+                           left join (
+                      select leader_id, parent_id, count(distinct material_id) as man_num
+                      from application.app_material_tag_busi_info
+                      where create_date between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d')
+                          and date_format(date_sub('2022-05-17', interval -1 day), '%Y%m%d')
+                        and tag_category_id = 1
+                        and parent_id = 60155
+                      group by leader_id, parent_id) d
+                                     on info.leader_id = d.leader_id
+                           left join
+                       (select leader_id, parent_id, count(distinct material_id)  as plan_num
+                        from application.app_material_tag_busi_info
+                        where create_date between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d')
+                            and date_format(date_sub('2022-05-17', interval -1 day), '%Y%m%d')
+                          and tag_category_id = 1
+                          and parent_id = 60156
+                        group by leader_id, parent_id) e
+                       on info.leader_id = e.leader_id
+
+                           left join
+                       (select leader_id, count(distinct signature) as hotmancount
+                        from (select signature
+                              from application.hot_material
+                              where media_id = 2
+                                and hot_date between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d') and date_format('2022-5-17', '%Y%m%d')) a
+                                 inner join
+                             (select leader_id, material_id
+                              from application.app_material_tag_busi_info
+                              where tag_category_id = 1
+                                and parent_id = 60155
+                                and leader_id in (select user_id
+                                                  from `jeecg-boot`.user_company
+                                                  where company_id in
+                                                        ('d57fecdcf7a94d009736d9c850731582',
+                                                         '5e46b5dea3d740eeb8ff1a2895015a4b'))) b
+                             on a.signature = b.material_id
+                        group by leader_id) f
+                       on info.leader_id = f.leader_id
+                           left join
+                       (select leader_id, count(distinct signature) as hotplancount
+                        from (select signature
+                              from application.hot_material
+                              where media_id = 2
+                                and hot_date between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d') and date_format('2022-5-17', '%Y%m%d')) a
+                                 inner join
+                             (select leader_id, material_id
+                              from application.app_material_tag_busi_info
+                              where tag_category_id = 1
+                                and parent_id = 60156
+                                and leader_id in (select user_id
+                                                  from `jeecg-boot`.user_company
+                                                  where company_id in
+                                                        ('d57fecdcf7a94d009736d9c850731582',
+                                                         '5e46b5dea3d740eeb8ff1a2895015a4b'))) b
+                             on a.signature = b.material_id
+                        group by leader_id) i
+                       on info.leader_id = i.leader_id) t
+         group by leader_name, sumcharge) t
+
+-- 汇总
+
+select
+       '' as rn,
+       '汇总' leader_name,
+       sum(leadercharge) as leadercharge,
+       ifnull(sum(hot_num),0) as hot_num,
+       ifnull(sum(hot_cost),0) as hot_cost,
+       concat(round(ifnull(sum(hot_num)/sum(material_num)*100,0),2),'%') as hot_rate,
+       ifnull(sum(material_num),0) as material_num,
+       ifnull(sum(material_num),0)  as  script_num,
+       ifnull(sum(plan_num),0) as plan_num,
+       ifnull(sum(hotplancount),0) as  hotplancount,
+       ifnull(sum(man_num),0) as man_num,
+       ifnull(sum(hotmancount),0) as hotmancount,
+       ifnull(sum(plan_num),0) as script_plan_num,
+       ifnull(sum(hotplancount),0) as  script_hotplancount,
+       ifnull(sum(man_num),0) as script_man_num,
+       ifnull(sum(hotmancount),0) as script_hotmancount,
+       '' as charge_rate
+from (
+         select leader_name,
+                sum(leadercharge) as leadercharge,
+                sum(hot_num)      as hot_num,
+                sum(material_num) as material_num,
+                sum(hot_cost)     as hot_cost,
+                sum(man_num)      as man_num,
+                sum(hotmancount)  as hotmancount,
+                sum(plan_num)     as plan_num,
+                sum(hotplancount) as hotplancount
+         from (
+                  select info.leader_id,
+                         case
+                             when info.leader_name like '%汇创%' then replace(leader_name, '(汇创)', '')
+                             else leader_name end as leader_name,
+                         info.leadercharge,
+                         hot_num,
+                         hot_cost,
+                         material_num,
+                         man_num,
+                         hotmancount,
+                         plan_num,
+                         hotplancount
+                  from (select leader_id, leader_name, leadercharge
+                        from (select leader_id, leader_name, sum(charge) as leadercharge
+                              from application.kuaishou_material_video_report_daily_dw
+                              where stat_date between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d') and date_format('2022-5-17', '%Y%m%d')
+                                and clip_company_id in
+                                    ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                and leader_id is not null
+                              group by leader_id, leader_name) a) info
+
+
+                           left join (
+                      select leader_id, count(1) as material_num
+                      from `jeecg-boot`.ctop_material_ascription
+                      where create_time between date_format(date_sub('2022-05-17', interval 6 day), '%Y-%m-%d')
+                          and date_format(date_sub('2022-05-17', interval -1 day), '%Y-%m-%d')
+                        and leader_id in (select user_id
+                                          from `jeecg-boot`.user_company
+                                          where company_id in
+                                                ('d57fecdcf7a94d009736d9c850731582',
+                                                 '5e46b5dea3d740eeb8ff1a2895015a4b'))
+                      group by leader_id) b
+                                     on info.leader_id = b.leader_id
+                           left join(
+                      select leader_id, sum(hot_num) as hot_num, sum(hot_cost) as hot_cost
+                      from (
+                               select b.leader_id, count(1) as hot_num, sum(hot_cost) as hot_cost
+                               from (select signature
+                                     from application.hot_material
+                                     where media_id = 2
+                                       and hot_date between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d') and date_format('2022-5-17', '%Y%m%d')) a
+                                        inner join
+                                    (select material_id, leader_id
+                                     from `jeecg-boot`.ctop_material_ascription
+                                     where leader_id in (select user_id
+                                                         from `jeecg-boot`.user_company
+                                                         where company_id in
+                                                               ('d57fecdcf7a94d009736d9c850731582',
+                                                                '5e46b5dea3d740eeb8ff1a2895015a4b')
+                                     )) b
+                                    on a.signature = b.material_id
+                                        left join(
+                                   select *
+                                   from application.hot_material_two_week_cost
+                                   where media_id = 2
+                               ) c
+                                                 on a.signature = c.signature
+                                        left join (select material_id, parent_id, parent_name
+                                                   from application.app_material_tag_busi_info
+                                                   where tag_category_id = 1
+                                                   group by material_id, parent_id) d
+                                                  on a.signature = d.material_id
+                               group by leader_id, a.signature) t
+                      group by leader_id) c
+                                    on info.leader_id = c.leader_id
+                           left join (
+                      select leader_id, parent_id, count(distinct material_id) as man_num
+                      from application.app_material_tag_busi_info
+                      where create_date between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d')
+                          and date_format(date_sub('2022-05-17', interval -1 day), '%Y%m%d')
+                        and tag_category_id = 1
+                        and parent_id = 60155
+                      group by leader_id, parent_id) d
+                                     on info.leader_id = d.leader_id
+                           left join
+                       (select leader_id, parent_id, count(distinct material_id)  as plan_num
+                        from application.app_material_tag_busi_info
+                        where create_date between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d')
+                            and date_format(date_sub('2022-05-17', interval -1 day), '%Y%m%d')
+                          and tag_category_id = 1
+                          and parent_id = 60156
+                        group by leader_id, parent_id) e
+                       on info.leader_id = e.leader_id
+
+                           left join
+                       (select leader_id, count(distinct signature) as hotmancount
+                        from (select signature
+                              from application.hot_material
+                              where media_id = 2
+                                and hot_date between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d') and date_format('2022-5-17', '%Y%m%d')) a
+                                 inner join
+                             (select leader_id, material_id
+                              from application.app_material_tag_busi_info
+                              where tag_category_id = 1
+                                and parent_id = 60155
+                                and leader_id in (select user_id
+                                                  from `jeecg-boot`.user_company
+                                                  where company_id in
+                                                        ('d57fecdcf7a94d009736d9c850731582',
+                                                         '5e46b5dea3d740eeb8ff1a2895015a4b'))) b
+                             on a.signature = b.material_id
+                        group by leader_id) f
+                       on info.leader_id = f.leader_id
+                           left join
+                       (select leader_id, count(distinct signature) as hotplancount
+                        from (select signature
+                              from application.hot_material
+                              where media_id = 2
+                                and hot_date between date_format(date_sub('2022-05-17', interval 6 day), '%Y%m%d') and date_format('2022-5-17', '%Y%m%d')) a
+                                 inner join
+                             (select leader_id, material_id
+                              from application.app_material_tag_busi_info
+                              where tag_category_id = 1
+                                and parent_id = 60156
+                                and leader_id in (select user_id
+                                                  from `jeecg-boot`.user_company
+                                                  where company_id in
+                                                        ('d57fecdcf7a94d009736d9c850731582',
+                                                         '5e46b5dea3d740eeb8ff1a2895015a4b'))) b
+                             on a.signature = b.material_id
+                        group by leader_id) i
+                       on info.leader_id = i.leader_id) t
+         group by leader_name) t

+ 287 - 0
sql/快手项目报表.sql

@@ -0,0 +1,287 @@
+--明细
+select concat(:date,'-',:enddate)                                                                                   as `日期`,
+       channle.project_name                                                                           as `项目名称`,
+       round(ifnull(sum(channle.in_charge), 0), 2)                                                    as `内部素材消耗`,
+       ifnull(sum(inner_num), 0)                                                                      as `内部消耗素材数`,
+       round(ifnull(sum(channle.in_charge) / sum(inner_num), 0), 2)                                   as `内部素材平均消耗`,
+       ifnull(sum(inner_first_cost_num), 0)                                                           as `内部昨日素材上新数`,
+       round(ifnull(sum(inner_first_cost_charge) / sum(inner_first_cost_num), 0), 2)                  as `内部昨日素材平均消耗`,
+       round(ifnull(sum(out_charge), 0), 2)                                                           as `外部素材消耗`,
+       ifnull(sum(outer_num), 0)                                                                      as `外部消耗素材数`,
+       round(ifnull(sum(out_charge) / sum(outer_num), 0), 2)                                          as `外部素材平均消耗`,
+       sum(first_cost_num)                                                                            as `外部昨日素材上新数`,
+       round(ifnull(sum(first_cost_charge) / sum(first_cost_num), 0), 2)                              as `外部昨日素材平均消耗`,
+       round(ifnull(sum(sum.sum_charge), 0), 2)                                                       as `总消耗`,
+       concat(round(ifnull(sum(channle.in_charge) / sum(sum.sum_charge) * 100, 0), 2), '%')           as `内部渗透率`,
+       concat(round(ifnull((sum(channle.in_charge) / sum(sum.sum_charge) -
+                            sum(channle_yes.in_charge) / sum(yes_sum.sum_charge)) /
+                           (sum(channle_yes.in_charge) / sum(yes_sum.sum_charge)) * 100, 0), 2), '%') as `环比`
+
+from (select project_id,
+             project_name,
+             count(distinct a.signature)                 as inner_num,
+             sum(charge)                                 as in_charge,
+             count(distinct c.signature)                 as inner_first_cost_num,
+             sum(if(c.signature is not null, charge, 0)) as inner_first_cost_charge
+      from application.kuaishou_material_video_report_daily_dw a
+               inner join (
+          select account_id
+          from `jeecg-boot`.ctop_user_allocation
+          where user_id in (
+              select user_id
+              from `jeecg-boot`.user_company
+              where company_id in ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+          )
+      ) b
+                          on a.account_id = b.account_id
+               left join (select signature
+                          from application.material_farst_cost_time
+                          where frast_cost_time = date_format(:date, '%Y%m%d')) c
+                         on a.signature = c.signature
+      where a.stat_date between date_format(:date, '%Y%m%d') and date_format(:enddate, '%Y%m%d')
+        and clip_company_id in
+            ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b',
+             '1648c7ceb4d449a9a13fbed7a8d9976c')
+        and channel_name = '内部'
+        and a.charge > 0
+
+      group by channel_name, project_id, project_name) channle
+         left join(
+    select project_id,
+           project_name,
+           sum(charge) as sum_charge
+    from application.kuaishou_material_video_report_daily_dw a
+             inner join (
+        select account_id
+        from `jeecg-boot`.ctop_user_allocation
+        where user_id in (
+            select user_id
+            from `jeecg-boot`.user_company
+            where company_id in ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+        )
+    ) b
+                        on a.account_id = b.account_id
+    where a.stat_date between date_format(:date, '%Y%m%d') and date_format(:enddate, '%Y%m%d')
+      and a.charge > 0
+    group by project_id, project_name
+) sum
+                  on channle.project_id = sum.project_id
+         left join(
+    select project_id,
+           project_name,
+           count(distinct a.signature)                 as outer_num,
+           sum(charge)                                 as out_charge,
+           count(distinct c.signature)                 as first_cost_num,
+           sum(if(c.signature is not null, charge, 0)) as first_cost_charge
+
+
+    from application.kuaishou_material_video_report_daily_dw a
+             inner join (
+        select account_id
+        from `jeecg-boot`.ctop_user_allocation
+        where user_id in (
+            select user_id
+            from `jeecg-boot`.user_company
+            where company_id in ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+        )
+    ) b
+                        on a.account_id = b.account_id
+
+             left join(select signature
+                       from application.material_farst_cost_time
+                       where frast_cost_time between date_format(:date, '%Y%m%d') and date_format(:enddate, '%Y%m%d')) c
+                      on a.signature = c.signature
+    where a.stat_date between date_format(:date, '%Y%m%d') and date_format(:enddate, '%Y%m%d')
+      and a.charge > 0
+      and (channel_type = 1 or channel_name = '素造')
+    group by channel_name, project_id, project_name
+) outc
+                  on channle.project_id = outc.project_id
+
+         left join (select project_id,
+                           project_name,
+                           sum(charge) as in_charge
+                    from application.kuaishou_material_video_report_daily_dw a
+                             inner join (
+                        select account_id
+                        from `jeecg-boot`.ctop_user_allocation
+                        where user_id in (
+                            select user_id
+                            from `jeecg-boot`.user_company
+                            where company_id in ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+                        )
+                    ) b
+                                        on a.account_id = b.account_id
+                    where a.stat_date  between date_format(date_sub(:date, interval datediff(:enddate,:date)+1 day), '%Y%m%d') and date_format(date_sub(:date, interval datediff(:enddate,:date)+1 day), '%Y%m%d')
+                      and clip_company_id in
+                          ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b',
+                           '1648c7ceb4d449a9a13fbed7a8d9976c')
+                      and channel_name = '内部'
+                    group by channel_name, project_id, project_name) channle_yes
+                   on channle.project_id = channle_yes.project_id
+         left join(
+    select project_id,
+           project_name,
+           sum(charge) as sum_charge
+    from application.kuaishou_material_video_report_daily_dw a
+             inner join (
+        select account_id
+        from `jeecg-boot`.ctop_user_allocation
+        where user_id in (
+            select user_id
+            from `jeecg-boot`.user_company
+            where company_id in ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+        )
+    ) b
+                        on a.account_id = b.account_id
+    where a.stat_date  between date_format(date_sub(:date, interval datediff(:enddate,:date)+1 day), '%Y%m%d') and date_format(date_sub(:date, interval datediff(:enddate,:date)+1 day), '%Y%m%d')
+    group by project_id, project_name
+) yes_sum
+                  on channle.project_id = yes_sum.project_id
+group by channle.project_name
+order by `总消耗` desc
+
+
+
+--汇总
+
+select concat(:date,'-',:enddate)                                                                                   as `日期`,
+       '汇总'                                                                          as `项目名称`,
+       round(ifnull(sum(channle.in_charge), 0), 2)                                                    as `内部素材消耗`,
+       ifnull(sum(inner_num), 0)                                                                      as `内部消耗素材数`,
+       round(ifnull(sum(channle.in_charge) / sum(inner_num), 0), 2)                                   as `内部素材平均消耗`,
+       ifnull(sum(inner_first_cost_num), 0)                                                           as `内部昨日素材上新数`,
+       round(ifnull(sum(inner_first_cost_charge) / sum(inner_first_cost_num), 0), 2)                  as `内部昨日素材平均消耗`,
+       round(ifnull(sum(out_charge), 0), 2)                                                           as `外部素材消耗`,
+       ifnull(sum(outer_num), 0)                                                                      as `外部消耗素材数`,
+       round(ifnull(sum(out_charge) / sum(outer_num), 0), 2)                                          as `外部素材平均消耗`,
+       sum(first_cost_num)                                                                            as `外部昨日素材上新数`,
+       round(ifnull(sum(first_cost_charge) / sum(first_cost_num), 0), 2)                              as `外部昨日素材平均消耗`,
+       round(ifnull(sum(sum.sum_charge), 0), 2)                                                       as 总消耗,
+       concat(round(ifnull(sum(channle.in_charge) / sum(sum.sum_charge) * 100, 0), 2), '%')           as `内部渗透率`,
+       concat(round(ifnull((sum(channle.in_charge) / sum(sum.sum_charge) -
+                            sum(channle_yes.in_charge) / sum(yes_sum.sum_charge)) /
+                           (sum(channle_yes.in_charge) / sum(yes_sum.sum_charge)) * 100, 0), 2), '%') as `环比`
+from (select project_id,
+             project_name,
+             count(distinct a.signature)                 as inner_num,
+             sum(charge)                                 as in_charge,
+             count(distinct c.signature)                 as inner_first_cost_num,
+             sum(if(c.signature is not null, charge, 0)) as inner_first_cost_charge
+      from application.kuaishou_material_video_report_daily_dw a
+               inner join (
+          select account_id
+          from `jeecg-boot`.ctop_user_allocation
+          where user_id in (
+              select user_id
+              from `jeecg-boot`.user_company
+              where company_id in ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+          )
+      ) b
+                          on a.account_id = b.account_id
+               left join (select signature
+                          from application.material_farst_cost_time
+                          where frast_cost_time  between date_format(:date, '%Y%m%d') and date_format(:enddate, '%Y%m%d')) c
+                         on a.signature = c.signature
+      where a.stat_date between date_format(:date, '%Y%m%d') and date_format(:enddate, '%Y%m%d')
+        and clip_company_id in
+            ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b',
+             '1648c7ceb4d449a9a13fbed7a8d9976c')
+        and channel_name = '内部'
+        and a.charge > 0
+
+      group by channel_name, project_id, project_name) channle
+         left join(
+    select project_id,
+           project_name,
+           sum(charge) as sum_charge
+    from application.kuaishou_material_video_report_daily_dw a
+             inner join (
+        select account_id
+        from `jeecg-boot`.ctop_user_allocation
+        where user_id in (
+            select user_id
+            from `jeecg-boot`.user_company
+            where company_id in ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+        )
+    ) b
+                        on a.account_id = b.account_id
+    where a.stat_date between date_format(:date, '%Y%m%d') and date_format(:enddate, '%Y%m%d')
+      and a.charge > 0
+    group by project_id, project_name
+) sum
+                  on channle.project_id = sum.project_id
+         left join(
+    select project_id,
+           project_name,
+           count(distinct a.signature)                 as outer_num,
+           sum(charge)                                 as out_charge,
+           count(distinct c.signature)                 as first_cost_num,
+           sum(if(c.signature is not null, charge, 0)) as first_cost_charge
+
+
+    from application.kuaishou_material_video_report_daily_dw a
+             inner join (
+        select account_id
+        from `jeecg-boot`.ctop_user_allocation
+        where user_id in (
+            select user_id
+            from `jeecg-boot`.user_company
+            where company_id in ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+        )
+    ) b
+                        on a.account_id = b.account_id
+
+             left join(select signature
+                       from application.material_farst_cost_time
+                       where frast_cost_time between date_format(:date, '%Y%m%d') and date_format(:enddate, '%Y%m%d')) c
+                      on a.signature = c.signature
+    where a.stat_date between date_format(:date, '%Y%m%d') and date_format(:enddate, '%Y%m%d')
+      and a.charge > 0
+      and (channel_type = 1 or channel_name = '素造')
+    group by channel_name, project_id, project_name
+) outc
+                  on channle.project_id = outc.project_id
+
+         left join (select project_id,
+                           project_name,
+                           sum(charge) as in_charge
+                    from application.kuaishou_material_video_report_daily_dw a
+                             inner join (
+                        select account_id
+                        from `jeecg-boot`.ctop_user_allocation
+                        where user_id in (
+                            select user_id
+                            from `jeecg-boot`.user_company
+                            where company_id in ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+                        )
+                    ) b
+                                        on a.account_id = b.account_id
+                    where a.stat_date  between date_format(date_sub(:date, interval datediff(:enddate,:date)+1 day), '%Y%m%d') and date_format(date_sub(:date, interval datediff(:enddate,:date)+1 day), '%Y%m%d')
+                      and clip_company_id in
+                          ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b',
+                           '1648c7ceb4d449a9a13fbed7a8d9976c')
+                      and channel_name = '内部'
+                    group by channel_name, project_id, project_name) channle_yes
+                   on channle.project_id = channle_yes.project_id
+         left join(
+    select project_id,
+           project_name,
+           sum(charge) as sum_charge
+    from application.kuaishou_material_video_report_daily_dw a
+             inner join (
+        select account_id
+        from `jeecg-boot`.ctop_user_allocation
+        where user_id in (
+            select user_id
+            from `jeecg-boot`.user_company
+            where company_id in ('d57fecdcf7a94d009736d9c850731582', '5e46b5dea3d740eeb8ff1a2895015a4b')
+        )
+    ) b
+                        on a.account_id = b.account_id
+    where a.stat_date  between date_format(date_sub(:date, interval datediff(:enddate,:date)+1 day), '%Y%m%d') and date_format(date_sub(:date, interval datediff(:enddate,:date)+1 day), '%Y%m%d')
+    group by project_id, project_name
+) yes_sum
+                  on channle.project_id = yes_sum.project_id
+
+

+ 75 - 0
sql/转户.sql

@@ -0,0 +1,75 @@
+SELECT
+	(
+		SELECT
+			CASE
+		WHEN media_id = 1 THEN
+			'头条'
+		WHEN media_id = 2 THEN
+			'快手'
+		WHEN media_id = 3 THEN
+			'头条内广'
+		ELSE
+			''
+		END
+		FROM
+			ctop_project
+		WHERE
+			id = t1.project_id
+	) AS '媒体',
+	(
+		SELECT
+			project_name
+		FROM
+			ctop_project
+		WHERE
+			id = t1.project_id
+	) AS '项目',
+	CONCAT('`',t1.account_id,'`' )  AS '账户id',
+	(
+		SELECT
+			realname
+		FROM
+			sys_user
+		WHERE
+			id = t1.transferor
+	) AS '转户人',
+	(
+		SELECT
+			realname
+		FROM
+			sys_user
+		WHERE
+			id = t1.assignee
+	) AS '受让人',
+	t1.transferor_date AS '转户人绩效统计截止日期',
+	t1.assignee_date AS '受让人绩效统计开始日期'
+FROM
+	ctop_transfer_account t1
+WHERE
+	t1.transferor_date >= '2022-01-01'
+AND t1.transferor_date <= '2022-01-31'
+and t1.transferor in(
+SELECT user_id  from user_company WHERE company_id = '4b10089775c040119e139087517aed88'
+)
+ORDER BY
+	t1.account_id
+
+
+
+
+
+	select company_name,
+       project_name,
+       user.realname,
+       leader.realname,
+       concat('`',account_id,'`') as account_id,
+       account_name,
+       charge
+from (select company_name, project_name, user_id, leader_id, account_id, account_name, charge
+      from application.app_kuaishou_account_report_busi_m
+      where stat_mon = 202206
+        and company_id = '4b10089775c040119e139087517aed88') a
+         left join `jeecg-boot`.sys_user user
+                   on a.user_id = user.id
+         left join `jeecg-boot`.sys_user leader
+                   on a.leader_id = leader.id