0

次のクエリがあります。

SELECT int_intrebari.id, COUNT( id_raspuns ) AS nr_raspunsuri
FROM int_intrebari, int_raspunsuri
WHERE int_intrebari.id = int_raspunsuri.id
GROUP BY id

foreach ステートメントを記述せずに、クエリから nr_raspunsuri を使用して最初のテーブルを更新することは可能ですか?

4

3 に答える 3

2

あなたはそうUPDATEすることができますJOIN

UPDATE int_intrebari i1
INNER JOIN
(
    SELECT id, COUNT( id_raspuns ) AS nr_raspunsuri
    FROM int_intrebari
    GROUP BY id 
) i2 ON i1.id = i2.id
SET i1.nr_raspunsuri = i2.nr_raspunsuri
于 2012-10-30T07:21:02.297 に答える
1

あなたはそれを次のようにすることができます-

update int_intrebari left join int_raspunsuri on int_intrebari.id =int_raspunsuri.id
set int_intrebari.column_to_update = int_raspunsuri.column_from_update_second_table
于 2012-10-30T07:22:18.067 に答える
0
UPDATE
  (SELECT int_intrebari.id, COUNT( id_raspuns) AS nr_raspunsuri
   FROM int_intrebari, int_raspunsuri
   WHERE int_intrebari.id = int_raspunsuri.id
   GROUP BY id) t1,
  int_raspunsuri t2
SET
  t2.nr_raspunsuri=t1.nr_raspunsuri
WHERE
  t1.id=t2.id
于 2012-10-30T07:17:20.637 に答える