[pgsql-jp: 25987] Re: 時間帯検索の重複チェック

Yu Ooasa you @ dearest.net
2002年 5月 16日 (木) 17:10:01 JST


Thu, 16 May 2002 16:20:55 +0900
	Hiroshi Ishiura <issy777 @ entrance-e.com> said:
>施設予約スケジュールのようなもの作っており、
>施設予約時間の重複チェックでいいSQL文が思いつきません。
>
>例えばreserveテーブルに以下のデータが入っていた場合
>date	   |start_time|end_time
>-----------------------
>2002-05-16 | 10:00:00  |13:00:00

>現状
>select * from reserve where date='$s_date' and start_time <= '$datetime'
>and end_time >='$datetime'
>
>これだとAの場合、重複であるとみなされるのですが、
>CやDのように開始時間はあいていたり、終了時間が空いていたりする場合も重複
>エラー処理をしたいのですが、スマートなSQL文の書き方はないでしょうか。

算数の問題だと思いますが

not (start >= 10 and start < 13 and end >= 10 and end < 13) and
not (start < 10 and end >= 10 and end < 13) and
not (start >= 10 and start < 13 and end >= 13) and
not (start < 10 and end > 13)

ならば真

# スマートかどうかはともかく
--
Yu Ooasa  E-mail: you @ dearest.net



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