我正在尝试创建一个更新table_1
的查询,其中列id_owner
的{{1}}列数超过5 rows
,需要设置列“ <{1}}“至owner id
这些用户拥有的所有行。
我尝试了几种不同的方法,并且每种方法都空了。有什么想法吗?
答案 0 :(得分:2)
将此UPDATE
查询与JOIN
一起使用即可实现此目的:
UPDATE table1 t1
JOIN
(
SELECT id_owner
FROM table1
GROUP BY id_owner
HAVING COUNT(*) > 5
) t2
ON t1.id_owner = t2.id_owner
SET t1.active = 3;
答案 1 :(得分:1)
update table_1
set active = 3
where owner_id in
(
select * from
(
select owner_id
from table_1
group by owner_id
having count(*) > 5
) x
)
答案 2 :(得分:1)
你可以试试这个: -
update table_1
set active = 3
where owner_id in
(
select * from
(
select owner_id
from table_1
group by owner_id
having count(*) > 5
) a
)