予約テーブルには、予約の開始日、開始時間、および期間が含まれています。開始時間は、就業時間の30分刻みで8:00..就業日の18:00です。期間も1日で30分刻みです。
CREATE TABLE reservation (
startdate date not null, -- start date
starthour numeric(4,1) not null , -- start hour 8 8.5 9 9.5 .. 16.5 17 17.5
duration Numeric(3,1) not null, -- duration by hours 0.5 1 1.5 .. 9 9.5 10
primary key (startdate, starthour)
);
テーブル構造は必要に応じて変更できます。
予約されていないテーブルで最初の無料の30分を見つける方法は?テーブルにが含まれている場合の式
startdate starthour duration
14 9 1 -- ends at 9:59
14 10 1.5 -- ends at 11:29, e.q there is 30 minute gap before next
14 12 2
14 16 2.5
結果は次のようになります。
starthour duration
11.5 0.5
おそらくPostgreSql9.2ウィンドウ関数を使用して、開始時間が前の行の開始時間+期間よりも大きい最初の行を検索する必要が
あります。この情報を返すselectステートメントの記述方法は?