pull_data.sql 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. WITH all_company_data as (
  2. SELECT company_id,new_cid,base,name,name_en,name_alias,history_names,legal_entities,reg_number,company_org_type,reg_location,estiblish_time,from_time,to_time,business_scope,reg_institute,approved_time,reg_status,reg_capital,org_number,org_approved_institute,parent_company_id,company_type,credit_code,score,cate_first_code,cate_second_code,cate_third_code,lat,lng,province_code,city_code,county_code,reg_capital_amount,reg_capital_currency,actual_capital_amount,actual_capital_currency,reg_status_std,social_security_staff_num,cancel_date,cancel_reason,revoke_date,revoke_reason,emails,phones,wechat_public_num,logo,crawled_time,create_time,update_time,deleted,lawyer_num,lawfirm_intro,competent_unit,certificate_validity,tel_info,ds
  3. FROM (
  4. SELECT *
  5. ,ROW_NUMBER() OVER(PARTITION BY company_id ORDER BY ds DESC ) AS num
  6. FROM (
  7. SELECT company_id,new_cid,base,name,name_en,name_alias,history_names,legal_entities,reg_number,company_org_type,reg_location,estiblish_time,from_time,to_time,business_scope,reg_institute,approved_time,reg_status,reg_capital,org_number,org_approved_institute,parent_company_id,company_type,credit_code,score,cate_first_code,cate_second_code,cate_third_code,lat,lng,province_code,city_code,county_code,reg_capital_amount,reg_capital_currency,actual_capital_amount,actual_capital_currency,reg_status_std,social_security_staff_num,cancel_date,cancel_reason,revoke_date,revoke_reason,emails,phones,wechat_public_num,logo,crawled_time,create_time,update_time,deleted,lawyer_num,lawfirm_intro,competent_unit,certificate_validity,tel_info,ds
  8. FROM winhc_ng.ads_company_v9
  9. WHERE ds = 20220111
  10. UNION ALL
  11. SELECT company_id,new_cid,base,name,name_en,name_alias,history_names,legal_entities,reg_number,company_org_type,reg_location,estiblish_time,from_time,to_time,business_scope,reg_institute,approved_time,reg_status,reg_capital,org_number,org_approved_institute,parent_company_id,company_type,credit_code,score,cate_first_code,cate_second_code,cate_third_code,lat,lng,province_code,city_code,county_code,reg_capital_amount,reg_capital_currency,actual_capital_amount,actual_capital_currency,reg_status_std,social_security_staff_num,cancel_date,cancel_reason,revoke_date,revoke_reason,emails,phones,wechat_public_num,logo,crawled_time,create_time,update_time,deleted,lawyer_num,lawfirm_intro,competent_unit,certificate_validity,tel_info,ds
  12. FROM winhc_ng.inc_ads_company_v9
  13. WHERE ds > 20220111
  14. ) AS all_t1
  15. ) AS all_t2
  16. WHERE all_t2.num = 1 and reg_status_std NOT LIKE '%销%' and (name LIKE '%公司%' or name LIKE '%合伙%') and company_type = 1
  17. )
  18. INSERT OVERWRITE TABLE out_winhc_data_analysis_pull_data PARTITION(ds='{latest_ds}')
  19. SELECT company_id,company_name,company_org_type,province_code,city_code,county_code,org_number,credit_code,reg_number,cate_first_code,cate_second_code,cate_third_code from (
  20. SELECT tt1.*,tt2.company_rank from (
  21. SELECT company_id,name as company_name,company_org_type,province_code,city_code,county_code,org_number,credit_code,reg_number,cate_first_code,cate_second_code,cate_third_code,ds from all_company_data as t1
  22. LEFT ANTI join (
  23. select * from out_winhc_data_analysis_pull_data where ds < '{latest_ds}'
  24. ) as t2
  25. on t1.company_id = t2.company_id
  26. ) as tt1
  27. left join (
  28. SELECT company_id,final_value as company_rank from calc_company_rank_out where ds = '{company_rank_latest_ds}'
  29. ) as tt2
  30. on tt1.company_id =tt2.company_id
  31. )
  32. ORDER by company_rank desc
  33. LIMIT {limit_num};