3

我正在尝试创建一个查询,该查询将更新table_1列的位置id_owner5 rows相同的多owner id,它需要将列“ active”设置为3用户拥有的所有行。

我尝试了几种不同的方法,但每种方法都是空的。有任何想法吗?

4

3 回答 3

3

使用此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;

请参阅此示例 SQLFiddle

于 2013-09-21T06:55:24.730 回答
2

你可以试试这个:-

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
)
于 2013-09-21T06:47:34.577 回答
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
)

SQLFiddle 演示

于 2013-09-21T06:46:55.850 回答