如果您只想使用优先级来更新表,它将看起来像:
update my_table x set popularity = ( select count(distinct state) from my_table where fruit = x.fruit )
如果要选择数据,则可以使用分析查询:
select state, fruit , count(distinct state) over ( partition by fruit ) as popularity from my_table
这提供了每个水果不同状态的数量。



