用netezza中的新值更新列

vatpfxk5  于 2021-08-13  发布在  Java
关注(0)|答案(1)|浏览(416)

我对解决这个问题有疑问。我的表有model\u name、device\u type、count\u device\u type和new\u device\u type。我想为每个型号更新当前设备类型列,使其只有一个设备类型(请参见表中的示例)

  1. **MODEL DEVICE_TYPE COUNT_DEVICE_TYPE NEW_DEVICE_TYPE**
  2. SAMUNG GALAXY S5 SMARTPHONE 100 SMARTPHONE
  3. SAMUNG GALAXY S5 PORTABLE PDA 30 SMARTPHONE
  4. SAMUNG GALAXY S5 HANDHELD 10 SMARTPHONE

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

  1. update tmp_BI_device_table a
  2. a.device_type = b.new_device_type
  3. from (
  4. select
  5. model
  6. ,device_type
  7. ,case when count(model)<40 then
  8. (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
  9. from tmp_BI_device_table
  10. group by 1,2
  11. )

我收到这个错误:

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

fhg3lkii1#

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

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

相关问题