Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- chd.id,
- chd.date,
- chd.prd_desc,
- rel.cas,
- rel.posibility,
- rel.match_type,
- chd.exporter,
- chd.importer
- FROM "customs_house_data" chd
- LEFT JOIN (
- SELECT
- row_number() over(w ORDER BY tmp.c desc) r,
- round(tmp.c/(sum(tmp.c) over(w)), 4) posibility,
- *
- FROM (
- SELECT customs_house_data_id, match_type, cas, count(*) c
- FROM customs_house_data_chem_rel chd_rel
- group by customs_house_data_id, cas, match_type
- ) tmp
- WINDOW w as (partition by customs_house_data_id)
- ) rel
- on chd.id = rel.customs_house_data_id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement