Advertisement
Pandaaaa906

Untitled

Sep 1st, 2022
1,576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SELECT
  2. chd.id,
  3. chd.date,
  4. chd.prd_desc,
  5. rel.cas,
  6. rel.posibility,
  7. rel.match_type,
  8. chd.exporter,
  9. chd.importer
  10.  
  11. FROM "customs_house_data" chd
  12.  
  13. LEFT JOIN (
  14. SELECT
  15. row_number() over(w  ORDER BY tmp.c desc) r,
  16. round(tmp.c/(sum(tmp.c) over(w)), 4) posibility,
  17. *
  18. FROM (
  19. SELECT customs_house_data_id, match_type, cas, count(*) c
  20. FROM customs_house_data_chem_rel chd_rel
  21. group by customs_house_data_id, cas, match_type
  22. ) tmp
  23. WINDOW w as (partition by customs_house_data_id)
  24. ) rel
  25. on chd.id = rel.customs_house_data_id
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement