1

mysqlイベント内でselectを実行してから、そのselectからのデータで別のテーブルを更新しようとしています。しかし、それは機能していないようです。

私がやっている:

BEGIN
select read_pub_id, read_artc_id, count(read_artc_id) as times_read from reads_t GROUP BY read_pub_id, read_artc_id;
update reads_totals set read_total = times_read where pub_id = read_pub_id and artc_id = read_artc_id;
update reads_totals set ts=now(); /*This is for testing*/
END

tsのみが更新されます。これは、イベントが機能していることを意味します。

ここに追加するwhileループはありますか?また、その方法は?これを行う正しい方法は何ですか?

これに関する私の以前の質問はここにあります:

https://stackoverflow.com/questions/13110393/doing-a-count-along-with-distinct-to-check-number-of-times-a-post-was-read

4

2 に答える 2

1

もしかして:

UPDATE reads_totals T
SET read_total = (SELECT count(read_artc_id) 
                  FROM reads_t R 
                  WHERE R.read_pub_id = T.pub_id 
                  AND R.read_artc_id = T.artc_id);

このクエリはのすべての行を更新しますがreads_totals、これが本当に意図したものかどうかはわかりません。

于 2012-10-29T04:51:33.327 に答える
1
 select read_pub_id, read_artc_id, count(read_artc_id) as times_read from reads_t 
 GROUP BY read_pub_id, read_artc_id;
 update reads_totals
 set read_total = (select count(read_artc_id) from reads_t rt 
 where pub_id = rt.read_pub_id 
 and artc_id = rt.read_artc_id);
于 2012-10-29T04:52:29.753 に答える