答案 0 :(得分:2)
这是一个奇怪的请求,但您可以使用row_number()
:
select t2.*,
(case when row_number() over (partition by name, region order by id) = 1
then t1.count
end) as count
from table2 t2 join
table1 t1
on t2.name = t1.name and t2.region = t1.region;
但是,如果您正在计算table2
中的值,那么有一种更简单的方法:
select t2.*,
(case when row_number() over (partition by name, region order by id) = 1
then count(*) over (partition by name, region)
end) as count
from table2 t2;
Table1
根本不需要。