我有来自查询的数据查询结果
select count(type_of_vegetation)as count,type_of_vegetation
from tb_patrol
group by type_of_vegetation
如下图所示:
count | type of vegetation
1 | Semak Belukar, Pepohonan
2 | Pakis, Sawit, Senduduk
1 | Pakis, Sawit, Ilalang, Akasia
49 | Sawit
15 | Pakis, Karet
17 | Semak Belukar
我想更新"植被类型的价值"其数量小于15的人数"其他"但是按照植被类型的条件组,如下例所示:
count | type of vegetation
1 | Others
2 | Others
1 | Others
49 | Sawit
15 | Pakis, Karet
17 | Semak Belukar
我使用postgres SQL。
答案 0 :(得分:0)
使用子查询和IN
运算符:
UPDATE tb_patrol
SET type_of_vegetation = 'Other'
WHERE type_of_vegetation IN (
select type_of_vegetation
from tb_patrol
group by type_of_vegetation
having count(type_of_vegetation) < 15
);