Sql 使用Netezza中的新值更新列

Sql 使用Netezza中的新值更新列,sql,case,netezza,Sql,Case,Netezza,我对解决这个问题有怀疑。我的表格有型号名称、设备类型、计数设备类型和新设备类型。 我想更新每个型号的当前设备类型列,使其只有一种设备类型(请参见表中的示例) 我已尝试此代码,但无法捕获新值: update tmp_BI_device_table a a.device_type = b.new_device_type from ( select model ,device_type ,case when count(model)<40 then

我对解决这个问题有怀疑。我的表格有型号名称、设备类型、计数设备类型和新设备类型。 我想更新每个型号的当前设备类型列,使其只有一种设备类型(请参见表中的示例)

我已尝试此代码,但无法捕获新值:

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
 )

如果要使用计数最高的设备类型,可以使用
first\u value()


你能分享你的输入和预期输出吗?并解释更新操作的条件。
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
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