[pgsql-jp: 31686] Re: 更新処理時に比較

mos_pgml angel @ cosmos-inc.net
2003年 12月 3日 (水) 11:47:16 JST


mosです。返信ありがとうございます。

> $sql="update usr_table set max_point=$point where usr_id=$uid AND
max_point
> < $point";
質問の意図は少し違ってまして、(文章が明確でなくごめんなさい)

まずテーブル構造は以下の
> > テーブル (ゲームID, 最高得点, 得点合計, 人数)
です。

このテーブルにはユーザID等は入れず、
最高点と得点合計と人数を記録し、
各ゲーム(ID)毎の最高得点と平均点を得ております。

で、
今複数回のクエリー(下記)で実現しているものを
一度のクエリーで処理できるものなのでしょうか?

> > 現在の処理
> >     1.テーブルロック
> >     2.現在値をセレクト
                select * from テーブル where ゲームid=gid
> >     3.(最高得点と比較:PHPで)
                if ($point > pg_result($rtn,0,最高得点) {
                    $sql2 = update テーブル set
                                 最高得点=$point,
                                 得点合計=(得点合計+$point),
                                 人数=(人数+1)
                                 where  ゲームid=gid
                } else {
                     //最高得点は更新しない
                    $sql2 = update テーブル set
                                 得点合計=(得点合計+$point),
                                 人数=(人数+1)
                                 where  ゲームid=gid
                }
> >     4.更新
> >     5.コミット




pgsql-jp メーリングリストの案内