3

table_1列に同じid_owner以上のものがある場所を更新するクエリを作成しようとしています。列 " " をそれらのユーザーが持っているすべての行に設定する必要があります。5 rowsowner idactive3

私はいくつかの異なる方法を試しましたが、それぞれが空になりました。何か案は?

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 に答える