postgresql - SQL Join on Multiple Matching Criterias -


is there way join 1 time, though there multiple rows same matching criteria? wanting join on name , region want count applied 1 of rows (no specific order).

enter image description here

this strange request, can use row_number():

select t2.*,        (case when row_number() on (partition name, region order id) = 1              t1.count         end) count table2 t2 join      table1 t1      on t2.name = t1.name , t2.region = t1.region; 

however, if counting values in table2, there easier way:

select t2.*,        (case when row_number() on (partition name, region order id) = 1              count(*) on (partition name, region)         end) count table2 t2; 

table1 not needed @ all.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -