このスキーマは、開始するのに十分なはずです
VISITORS
id
name
... other atomic data
RESOURCES
id
name
... other atomic data
RESERVATIONS
id
visitor
resource
fromdate
tilldate
したがって、部屋番号 200 を 11 月 19 日の 10:00 から 12:00 まで予約したい場合、「訪問者」フィールドが訪問者テーブルのエントリ「リソース」を指すレコードが予約テーブルに存在します。フィールドはリソーステーブルの部屋 200 のエントリを指し、'fromdate' は 10:00 19-11-2012 に等しくなり、'tilldate' は '12:00 19-11-2012' に等しくなります。
次のように、特定の日時に予約されているリソースを表示するクエリを作成できます。
select resources.name, visitors.name
from resources inner join reservations on resources.id = reservations.resource
inner join visitors on reservations.visitor = visitors.id
where reservations.fromdate <= "2012-11-19 06:00"
and reservations.tilldate >= "2012-11-19 23:59"
特定の時間にどのリソースが空いているかを示すクエリ
select resources.name
from resources
where not exists (select 1 from reservations
where reservations.resource = resources.id
and reservations.fromdate >= "2012-11-19 10:00"
and reservations.tilldate <= "2012-11-19 12:00")
誰かが「毎週水曜日に来ます」と言った場合、アプリケーション プログラムは、必要なリソース、日時に応じて「reservations」テーブルに複数の行を挿入できるほどスマートでなければなりません。
また、次の質問も参照してください:予約サイトのデータベース テーブル