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).
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
Post a Comment