Advertisement
laris_fdz

Untitled

Dec 16th, 2022
1,260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --период покрытия в новинках
  2.  drop table if exists tmp_cover_old;
  3.  
  4. create temp table tmp_cover_old (store bigint, supp varchar, cover bigint)
  5.     with (appendonly = 'true', compresslevel = '1', orientation = 'column', compresstype = zstd)
  6.         distributed randomly;
  7.  
  8. insert into tmp_cover_old (store, supp, cover)
  9.     select lmv.SPSSITE AS store
  10.         , f.FOUCNUF AS supp
  11.         , max(1 + coalesce(lmv.SPSDP,0) + coalesce(lmv.SPSDR,0) + coalesce(lmv.SPSXDDP,0) + coalesce(lmv.SPSXDDR,0)
  12.             - coalesce((lmv2.DELIVERY_EXC),0) + coalesce(lmv1.R_SROK,0)) AS cover
  13.     from gold_refgwr_ods.v_lmv_fouscheme lmv
  14.     JOIN gold_refcesh_ods.v_foudgene f ON f.FOUCFIN =lmv.SPSCFIN and f.is_actual = '1'
  15.     JOIN gold_refgwr_ods.v_lmv_supfrancorep lmv1 ON lmv1.R_SUPP =f.FOUCNUF AND lmv1.R_STORE = lmv.SPSSITE and lmv1.is_actual = '1'
  16.     LEFT JOIN gold_refgwr_ods.v_lmv_intfouscheme_exception lmv2 ON cast (lmv2.SUPPLIER as text) = f.FOUCNUF AND lmv2.site =lmv.SPSSITE and lmv2.is_actual = '1'
  17.     where current_date between lmv.SPSDDEB and lmv.SPSDFIN
  18.     and lmv.is_actual = '1'
  19.     group by lmv.SPSSITE, f.FOUCNUF;
  20.  
  21.    
  22. --период покрытия из источника для голда, отображается в бланке заказа Голд в репортс
  23. drop table if exists tmp_cover;
  24. create temp table tmp_cover (store int, supp varchar, cover int)
  25.     with (appendonly = 'true', compresslevel = '1', orientation = 'column', compresstype = zstd)
  26.         distributed randomly;
  27.  
  28. insert into tmp_cover (store, supp, cover)
  29. SELECT rep_site, rep_sup, MAX(rep_coverp) as rep_coverp
  30. FROM  gold_refgwr_ods.v_lmv_intstockrep_hist_v2 v
  31. where rep_coverp >= 0 and
  32. exists (
  33. select 1 from
  34. (select rep_site, rep_sup, MAX(rep_dcre) as latest_rep_dcre
  35. FROM  gold_refgwr_ods.v_lmv_intstockrep_hist_v2
  36. group by rep_site, rep_sup) as latest
  37. where latest.rep_site = v.rep_site and
  38. latest.rep_sup = v.rep_sup and
  39. latest.latest_rep_dcre = v.rep_dcre
  40. )
  41. group by rep_site, rep_sup;
  42.  
  43. --сравниваем обе версии
  44. select o.*, n.*,
  45. (coalesce(o.store,0) != coalesce(n.store, 0) or
  46. coalesce(o.supp,'0') != coalesce(n.supp,'0')) as compare
  47. from tmp_cover_old o
  48. left join tmp_cover n
  49. on
  50. o.store = n.store and
  51. o.supp = n.supp
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement