在 Netezza 中使用新值更新列

Update column with new value in Netezza

我对解决这个问题有疑问。我的 table 有 model_name、device_type、count_device_type 和 NEW_device_type. 我想为每个模型更新我当前的 device_type 列,使其只有一个 device_type(请参阅 table 中的示例)

**MODEL               DEVICE_TYPE    COUNT_DEVICE_TYPE          NEW_DEVICE_TYPE**

SAMUNG GALAXY S5      SMARTPHONE             100                SMARTPHONE
SAMUNG GALAXY S5      PORTABLE PDA           30                 SMARTPHONE
SAMUNG GALAXY S5      HANDHELD               10                 SMARTPHONE

我试过这段代码,但无法捕捉到新值:

update tmp_BI_device_table a
a.device_type = b.new_device_type
from (
     select
     model
     ,device_type
     ,case when count(model)<40 then 
     (select distinct device_type from tmp_BI_dim_device_ref a group by model, device_type having count(model)>10 ) else device_type end as new_device_type
from tmp_BI_device_table
group by 1,2
 )

我收到此错误:

ERROR:  12 : More than one tuple returned by a subselect used as an expression

如果你想要计数最高的设备类型,你可以使用first_value():

select model, device_type, count(*),
       first_value(device_type) over (partition by model order by count(*) desc) as imputed_device_type
from tmp_BI_device_table
group by 1, 2