SELECT sum(tab.add_user) over(partition by type order by date_time) as all_user,tab.add_user,tab.date_time,current_timestamp() from
(SELECT b.date_time,CASE WHEN a.num is null THEN 0 ELSE a.num end as add_user,'1' type from
(SELECT date_time from default.date_table WHERE date_time>'2019-04-16'
and date_time<current_date()) b LEFT JOIN (SELECT day date_time,count(1) num from (SELECT id_card,min(day) day from default.app_activate_credit
GROUP BY id_card)a1 GROUP BY day) a on a.date_time=b.date_time) tab;
--app.active_black:激活人员的黑名单
INSERT OVERWRITE TABLE app.active_black
SELECT a.id_card,b.fromtable,b.starttime,b.endtime,substr(b.starttime,0,10),b.reasoncode,'1' from
(SELECT id_card,min(`time`) time from default.app_activate_credit GROUP BY id_card) a
INNER JOIN (SELECT idcard,starttime,fromtable,endtime,reasoncode from default.blacklist_total WHERE sfhmd=1)b on a.id_card=b.idcard;
--app.active_black_hiscount:激活黑名单历史统计
insert overwrite table app.active_black_hiscount
select date_time,sum(add_num) over(partition by sfhmd order by date_time) all_num,add_num from
(select a.date_time date_time,case when b.startday is null then 0 else b.num end as add_num,'1' sfhmd from default.date_table a left outer join
(select startday,count(1) num from app.active_black group by startday) b on a.date_time=b.startday) tab;
--app.total_black_hiscount:黑名单全量历史统计
insert overwrite table app.total_black_hiscount
select date_time,sum(add_num) over(partition by sfhmd order by date_time) all_num,add_num from
(select a.date_time date_time,case when b.startday is null then 0 else b.num end as add_num,'1' sfhmd from default.date_table a left outer join
(select day startday,count(1) num from (select idcard,min(substr(starttime,0,10)) day from default.blacklist_total WHERE sfhmd='1' group by idcard)tb group by day)
b on a.date_time=b.startday) tab;
--credit_active_total:激活环比同比表
insert overwrite table app.credit_active_total
select
i.date_time as date_time,
i.active_total_user as active_total_user,
case when i.active_total_user_hb is null then 0.00 else i.active_total_user_hb end as active_total_user_hb,
case when j.active_total_user_tb is null then 0.00 else j.active_total_user_tb end as active_total_user_tb,
case when k.active_black_user is null then 0 else k.active_black_user end as active_black_user,
case when k.active_black_user_hb is null then 0 else k.active_black_user_hb end as active_black_user_hb,
case when l.active_black_user_tb is null then 0 else l.active_black_user_tb end as active_black_user_tb,
case when m.blacklist is null then 0 else m.blacklist end as blacklist,
case when m.blacklist_hb is null then 0 else m.blacklist_hb end as blacklist_hb,
case when n.blacklist_tb is null then 0 else n.blacklist_tb end as blacklist_tb
from
(
select
a.date_time as date_time,
a.total_driver as active_total_user,
round((a.total_driver-b.total_driver)/b.total_driver,6)*100 as active_total_user_hb
from (select *,row_number() over(order by date_time desc ) xh from app.credit_activate_stat_his) a
inner join (select *,row_number() over(order by date_time desc ) xh from app.credit_activate_stat_his) b on a.xh=b.xh-1
) i,
(
select
c.date_time as date_time,
round((c.total_driver-d.total_driver)/d.total_driver,6)*100 as active_total_user_tb
from app.credit_activate_stat_his c inner join app.credit_activate_stat_his d on c.date_time=date_add(d.date_time,30)
) j,
(
select
e.date_time as date_time,
e.all_num active_black_user,
round((e.all_num-f.all_num)/f.all_num,6)*100 as active_black_user_hb
from (select * from app.active_black_hiscount where date_time<current_date() and date_time>'2019-05-16') e inner join
(select * from app.active_black_hiscount where date_time<current_date() and date_time>'2019-05-16') f on e.date_time = date_add(f.date_time,1)
) k,
(
select
g.date_time as date_time,
round((g.all_num-h.all_num)/h.all_num,6)*100 as active_black_user_tb
from (select * from app.active_black_hiscount where date_time<current_date()) g
inner join
(select * from app.active_black_hiscount where date_time<current_date()) h on g.date_time = date_add(h.date_time,30)
) l,
(
select a1.date_time date_time,a1.all_num blacklist,round((a1.all_num-b1.all_num)/b1.all_num,6)*100 as blacklist_hb from
app.total_black_hiscount a1 inner join app.total_black_hiscount b1 on a1.date_time= date_add(b1.date_time,1)
) m,
(
select a2.date_time date_time,round((a2.all_num-b2.all_num)/b2.all_num,6)*100 as blacklist_tb from
app.total_black_hiscount a2 inner join app.total_black_hiscount b2 on a2.date_time= date_add(b2.date_time,30)
)n where i.date_time=j.date_time and j.date_time=k.date_time and k.date_time=l.date_time and l.date_time=m.date_time and m.date_time=n.date_time order by date_time desc;
--app.credit_total :信用数据总计表
insert overwrite table app.driver_gy_tongji
select tab.date_time,add_user,sum(tab.add_user) over(partition by type order by date_time) as all_user from
(SELECT a.date_time,CASE WHEN b.add_num is null THEN 0 ELSE b.add_num end as add_user,'1' type from
(SELECT date_time from default.date_table WHERE date_time<current_date()) a LEFT JOIN
(select date_time,count(1) add_num from (SELECT sfzmhm,min(substr(cclzrq,0,10)) date_time
from default.drivinglicense_gy_all GROUP BY sfzmhm) drv group by date_time) b on a.date_time=b.date_time)tab;
case when lfy1.total_driver_tb is null then 0 ELSE lfy1.total_driver_tb end as total_driver_tb,
case when lfy1.add_driver_tb is null then 0 ELSE lfy1.add_driver_tb end as add_driver_tb,
case when lfy2.total_driver_hb is null then 0 ELSE lfy2.total_driver_hb end as total_driver_hb,
case when lfy2.add_driver_hb is null then 0 ELSE lfy2.add_driver_hb end as add_driver_hb
from
(select a.date_time,a.add_user,a.all_user,
round((a.all_user-b.all_user)/b.all_user,6)*100 as total_driver_tb,
round((a.add_user-b.add_user)/b.add_user,6)*100 as add_driver_tb
from app.driver_gy_tongji a inner join
app.driver_gy_tongji b on a.date_time=date_add(b.date_time,30))lfy1
left outer join
(select e.date_time,
round((e.all_user-f.all_user)/f.all_user,6)*100 as total_driver_hb,
round((e.add_user-f.add_user)/f.add_user,6)*100 as add_driver_hb
from app.driver_gy_tongji e inner join
app.driver_gy_tongji f on e.date_time=date_add(f.date_time,1))lfy2
on lfy1.date_time=lfy2.date_time)lfy,default.credit_total wjc,app.credit_active_total lfy01 where lfy.date_time=wjc.date_time and lfy.date_time=lfy01.date_time;
from (SELECT b.* from default.app_activate_credit a INNER JOIN
(SELECT * from default.credit_score_mining_out WHERE eval_day=trunc(current_date(),'MM')) b on a.id_card=b.idcard_no)tab where eval_day= trunc(current_date(),'MM');
insert into app.credit_month_average_month_all select
trunc(current_date(),'MM'),
avg(b_score),
current_timestamp,
'0'
from default.credit_score_mining_out where eval_day= trunc(current_date(),'MM');
SELECT act_type2,act_type1,sum(times) total,date_sub(eval_day,1) cal_date,score_type,current_timestamp(),'0' from
default.credit_action_times_coe
WHERE eval_day=current_date() GROUP BY act_type2,act_type1,score_type,eval_day ;
INSERT into table app.credit_change_analysis_day
SELECT act_type2,act_type1,sum(times) total,date_sub(eval_day,1) cal_date,score_type,current_timestamp(),'1' from
(
SELECT b.* from default.app_activate_credit a INNER JOIN (SELECT * from
credit_action_times_coe WHERE eval_day=current_date() ) b on a.id_card=b.idcard_no
)tab
GROUP BY act_type2,act_type1,score_type,eval_day ;
--信用雷达-----------------------------
insert overwrite table app.credit_radar select 1,'违法行为',avg(crime_percent_rank),date_add(eval_day,-1),current_timestamp(),'0' from default.credit_score_mining_out where eval_day=current_date() group by eval_day;
insert into table app.credit_radar select 1,'违法行为',avg(crime_percent_rank),date_add(eval_day,-1),current_timestamp(),'1' from
(select * from default.app_activate_credit a inner join (select * from default.credit_score_mining_out where eval_day=current_date())b on a.id_card=b.idcard_no)tab group by eval_day;
insert into app.credit_radar select 2,'安全行驶',avg(accident_percent_rank),date_add(eval_day,-1),current_timestamp(),'0' from default.credit_score_mining_out where eval_day=current_date() group by eval_day;
insert into app.credit_radar select 2,'安全行驶',avg(accident_percent_rank),date_add(eval_day,-1),current_timestamp(),'1' from
(select * from default.app_activate_credit a inner join (select * from default.credit_score_mining_out where eval_day=current_date())b on a.id_card=b.idcard_no)tab group by eval_day;
insert into app.credit_radar select 3,'基础信息',avg(per_info_rank),date_add(eval_day,-1), current_timestamp(),'0' from default.credit_score_mining_out where eval_day=current_date() group by eval_day;
insert into app.credit_radar select 3,'基础信息',avg(per_info_rank),date_add(eval_day,-1), current_timestamp(),'1' from
(select * from default.app_activate_credit a inner join (select * from default.credit_score_mining_out where eval_day=current_date())b on a.id_card=b.idcard_no)tab group by eval_day;
insert into app.credit_radar select 4,'文明活动',avg(good_act_rank),date_add(eval_day,-1),current_timestamp(),'0' from default.credit_score_mining_out where eval_day=current_date() group by eval_day;
insert into app.credit_radar select 4,'文明活动',avg(good_act_rank),date_add(eval_day,-1),current_timestamp(),'1' from
(select * from default.app_activate_credit a inner join (select * from default.credit_score_mining_out where eval_day=current_date())b on a.id_card=b.idcard_no)tab group by eval_day;
insert into app.credit_radar select 5,'信用履约',avg(task_percent_rank),date_add(eval_day,-1) ,current_timestamp(),'0' from default.credit_score_mining_out where eval_day=current_date() group by eval_day;
insert into app.credit_radar select 5,'信用履约',avg(task_percent_rank),date_add(eval_day,-1) ,current_timestamp(),'1' from
(select * from default.app_activate_credit a inner join (select * from default.credit_score_mining_out where eval_day=current_date())b on a.id_card=b.idcard_no)tab group by eval_day;
--score_record---------------------------
insert overwrite table app.credit_score_record_day SELECT idcard_no,eval_day,substr(eval_day,1,7),b_score,per_info_score+total_no_bad_score+total_task_add_score+total_good_act_score,abs(total_crime_score+total_acci_score+total_task_m_score),crime_percent_rank,accident_percent_rank,per_info_rank,good_act_rank,task_percent_rank,b_rank,cast((tb.num-b_rank)/tb.num as decimal(38,6))*10000 FROM (select * from default.credit_score_mining_out where eval_day=current_date()) a INNER JOIN (SELECT count(1) num from default.credit_score_mining_out WHERE eval_day=current_date() ) tb on 1=1;
insert overwrite table app.credit_score_record_day_new SELECT idcard_no,substr(eval_day,1,7),a_score,big_level,small_level,cast((tb.num-a_rank)/tb.num as decimal(38,6))*10000,a_rank FROM (select idcard_no,eval_day,a_score,big_level,small_level,a_rank from (select b1.*,row_number() over(partition by idcard_no order by eval_day asc) evalrank from (select a0.* from (select idcard_no,eval_day,a_score,big_level,small_level,a_rank from default.credit_score_mining_out where eval_day>trunc(current_date(),'MM')) a0 left outer join (select idcard_no from default.credit_score_mining_out where eval_day=trunc(current_date(),'MM')) a1 on a0.idcard_no=a1.idcard_no where a1.idcard_no is null)b1 ) b2 where evalrank=1) a INNER JOIN (SELECT count(1) num from default.credit_score_mining_out WHERE eval_day=current_date()) tb on 1=1;
INSERT OVERWRITE TABLE app.credit_score_record_everyday SELECT a.id_card,a.gmt_evaluate,a.month_evaluate,a.credit_hide_score,b.credit_display_score,b.credit_big_level_code,b.credit_small_level_code,b.credit_score_rate,a.increase_score,a.deduction_score,a.traffic_compliance,a.safe_driving,a.base_info,a.civilized_activity,a.credit_compliance,b.credit_display_score_rank,a.credit_hide_score_rank,a.credit_hide_score_rate from app.credit_score_record_day a INNER JOIN app.credit_score_record_month b on a.id_card=b.id_card;
insert into app.credit_score_record_everyday SELECT a.id_card,a.gmt_evaluate,a.month_evaluate,a.credit_hide_score,b.credit_display_score,b.credit_big_level_code,b.credit_small_level_code,b.credit_score_rate,a.increase_score,a.deduction_score,a.traffic_compliance,a.safe_driving,a.base_info,a.civilized_activity,a.credit_compliance,b.credit_display_score_rank,a.credit_hide_score_rank,a.credit_hide_score_rate from app.credit_score_record_day a INNER JOIN app.credit_score_record_day_new b on a.id_card=b.id_card;
(SELECT b.* from default.app_activate_credit a1 INNER JOIN app.credit_score_record_everyday b on a1.id_card=b.id_card)tab) a
INNER JOIN (SELECT count(1) num from default.app_activate_credit a1l INNER JOIN app.credit_score_record_everyday bl on a1l.id_card=bl.id_card) tb on 1=1;
insert into app.credit_score_record
select *,'0' from app.credit_score_record_everyday;
--driver_type_stat----------
insert into two_customer_one_danger select distinct SFZMHM as idCard,case when SYXZ in ('B','C','D','E','R') then 1 else 0 end as flag from vehicle_gy_day where SYQ='2';
TRUNCATE TABLE default.driver_type;
insert into table default.driver_type SELECT DISTINCT a.idcard,1 as type from (SELECT DISTINCT idcard from default.blacklist_total where sfhmd='1' and substr(starttime,0,10)>'2009-09-05' and endtime>current_date())a INNER JOIN (SELECT DISTINCT id_card from default.app_activate_credit) b on a.idcard=b.id_card;
insert into table default.driver_type select tab2.idcard,2 as type from (select distinct tab1.idcard from (SELECT DISTINCT a.id_card idcard from default.app_activate_credit a LEFT OUTER JOIN
(SELECT DISTINCT idcard from default.blacklist_total where sfhmd='1') b on a.id_card=b.idcard WHERE b.idcard is null) tab1 left outer join (select distinct idcard from default.two_customer_one_danger) c
on tab1.idcard=c.idcard where c.idcard is null) tab2 left outer join (select distinct jszh from default.vio_violation_all) d on tab2.idcard=d.jszh where d.jszh is null;
insert into table default.driver_type select tab2.idcard,3 as type from (select distinct tab1.idcard from (SELECT DISTINCT a.id_card idcard from default.app_activate_credit a
LEFT OUTER JOIN (SELECT DISTINCT idcard from default.blacklist_total where sfhmd='1') b on a.id_card=b.idcard WHERE b.idcard is null) tab1 left outer join (select distinct
idcard from default.two_customer_one_danger) c on tab1.idcard=c.idcard where c.idcard is null) tab2 left outer join (select distinct jszh from default.vio_violation_all)
d on tab2.idcard=d.jszh where d.jszh is not null;
insert into table default.driver_type SELECT tab3.idcard,3 as type from (SELECT DISTINCT tab1.idcard from (select DISTINCT a.idcard from default.two_customer_one_danger a where a.flag=0) tab1
LEFT OUTER JOIN (SELECT DISTINCT idcard from default.blacklist_total where sfhmd='1') tab2 on tab1.idcard=tab2.idcard WHERE tab2.idcard is null ) tab3 LEFT OUTER JOIN
(select DISTINCT id_card from default.app_activate_credit) d on tab3.idcard=d.id_card WHERE d.id_card is not null;
insert into table default.driver_type SELECT tab3.idcard,4 as type from (SELECT DISTINCT tab1.idcard from (select DISTINCT a.idcard from default.two_customer_one_danger a where a.flag=1) tab1
LEFT OUTER JOIN (SELECT DISTINCT idcard from default.blacklist_total where sfhmd='1') tab2 on tab1.idcard=tab2.idcard WHERE tab2.idcard is null ) tab3 LEFT OUTER JOIN
(select DISTINCT id_card from default.app_activate_credit) d on tab3.idcard=d.id_card WHERE d.id_card is not null;
INSERT OVERWRITE TABLE default.driver_type_stat SELECT type as driver_type,case when type='1' then '黑名单驾驶人' when type='2' then '疑似荷包驾驶人' when type='3'
then '普通驾驶人' ELSE '两客一危驾驶人' end as driver_type_name,num as total_driver,date_sub(current_date(),1) as date_time from(SELECT type,count(1) num
select rank() over(partition by type order by a_rank,score_c desc) a_rank,t2.xm,t1.idcard_no,t2.xb,t2.zjcx,t1.big_level,t1.small_level,
t1.a_score,t1.score_c,t1.rank_c,current_timestamp(),'0',substr(current_date(),0,7) from
(
select rank() over(partition by type order by a1.a_rank) a_rank,a1.a_score,a1.big_level,a1.small_level,a1.a_score-a2.a_score score_c,a2.a_rank-a1.a_rank rank_c,a1.idcard_no,'0' type from
(select a_rank,a_score,idcard_no,big_level,small_level,'0' as type from default.credit_score_mining_out where eval_day=current_date() order by a_rank limit 200)a1,
(select a_rank,a_score,idcard_no from default.credit_score_mining_out where eval_day=add_months(current_date(),-1) ) a2 where a1.idcard_no=a2.idcard_no
) t1
INNER JOIN (SELECT sfzmhm,xb,xm,max(zjcx) zjcx from default.drivinglicense_gy_all GROUP BY sfzmhm,xb,xm) t2 on t1.idcard_no=t2.sfzmhm;
insert into app.credit_ranking
select rank() over(partition by type order by a_rank,score_c desc) a_rank,t2.xm,t1.idcard_no,t2.xb,t2.zjcx,t1.big_level,t1.small_level,
t1.a_score,t1.score_c,t1.rank_c,current_timestamp(),'1',substr(current_date(),0,7) from
(
select rank() over(partition by type order by a1.a_rank) a_rank,a1.a_score,a1.big_level,a1.small_level,a1.a_score-a2.a_score score_c,a2.a_rank-a1.a_rank rank_c,a1.idcard_no,'1' type from
(select a_rank,a_score,idcard_no,big_level,small_level,'1' as type from
(select c1.* from default.credit_score_mining_out c1 inner join (select distinct id_card from default.app_activate_credit) c2 on c1.idcard_no=c2.id_card) c01
where eval_day=current_date() order by a_rank limit 200)a1,
(select a_rank,a_score,idcard_no from
(select c1.* from default.credit_score_mining_out c1 inner join (select distinct id_card from default.app_activate_credit) c2 on c1.idcard_no=c2.id_card) c02
where eval_day=add_months(current_date(),-1) ) a2 where a1.idcard_no=a2.idcard_no
) t1
INNER JOIN (SELECT sfzmhm,xb,xm,max(zjcx) zjcx from default.drivinglicense_gy_all GROUP BY sfzmhm,xb,xm) t2 on t1.idcard_no=t2.sfzmhm;
@@ -31,7 +31,7 @@ select date_time,sum(add_num) over(partition by sfhmd order by date_time) all_nu
insert overwrite table app.total_black_hiscount
select date_time,sum(add_num) over(partition by sfhmd order by date_time) all_num,add_num from
(select a.date_time date_time,case when b.startday is null then 0 else b.num end as add_num,'1' sfhmd from default.date_table a left outer join
(select day startday,count(1) num from (select idcard,min(substr(starttime,0,10)) day from default.blacklist_total group by idcard)tb group by day)
(select day startday,count(1) num from (select idcard,min(substr(starttime,0,10)) day from default.blacklist_total WHERE sfhmd='1' group by idcard)tb group by day)