1

私は2つのテーブルを持っています:

|| *id* || *calendar_type* || *event_name* || *event_details* || *start_date* || *end_date* || *closed_date* || *time_start* || *time_end* ||
|| 1 || OPEN || AVAILABLE BLOCK || _NULL_ || 2013-01-01 || 2013-12-31 || 0000-00-00 || 08:00:00 || 08:59:00 ||
|| 2 || OPEN || AVAILABLE BLOCK || _NULL_ || 2013-01-01 || 2013-12-31 || _NULL_ || 09:00:00 || 09:59:00 ||
|| 3 || OPEN || AVAILABLE BLOCK || _NULL_ || 2013-01-01 || 2013-12-31 || _NULL_ || 10:00:00 || 10:59:00 ||
|| 4 || OPEN || AVAILABLE BLOCK || _NULL_ || 2013-01-01 || 2013-12-31 || _NULL_ || 13:00:00 || 13:59:00 ||

Appointment_Calendar テーブル: 利用可能な時間ブロックの日付と時刻、および閉じられているブロックの日付と時刻を保持します。

|| *id* || *start_time* || *duration_min* || *customer_id* || *consignee* || *trucker_name* || *email* || *phone* || *pallet_total* || *freight_type* || *notes* || *reserved_on* || *is_cancelled* ||
|| 1 || 2013-01-22 09:00:00 || 01:00:00 || 0 ||  || Testing ||  ||  || 20 || DELIVERY || this is a test || 2013-01-22 19:15:06 || 0 ||
|| 2 || 2013-01-22 10:00:00 || 01:00:00 || 0 ||  || Trucker 2 ||   ||  || 12 || DELIVERY ||  || 2013-01-22 19:16:37 || 0 ||
|| 4 || 2013-01-23 08:00:00 || 01:00:00 || 0 ||  || Trucker 3 ||  ||  || 10 || DELIVERY ||  || 2013-01-22 20:32:18 || 0 ||

ここでの目標は、使用可能なすべてのブロックのリストを取得し (appoint_calendar から) 1 つのクエリ (おそらく 2 つ) を作成し、予定に含まれていない (予約されていない) または特定の日付に閉じられていない時間だけを返すことです。以下の SQL はこれを行いますが、サブクエリを導入してすべての予定の日付または時刻を省略すると、コメント アウトされたセグメントが表示され、使用可能なすべての予定_カレンダー ブロックが消えます。利用可能な時間ブロックのみを表示することを望んでいました

SELECT DATE('2013-01-23 08:00:00')as today,appointment_calendar.*
FROM appointment_calendar 
WHERE calendar_type='OPEN'
AND
 DATE( '2013-01-23 08:00:00') BETWEEN start_date AND end_date
AND
 DATE( '2013-01-23 08:00:00') 
  NOT IN (SELECT closed_date  FROM appointment_calendar WHERE calendar_type='CLOSED')

/*  This does not work somehow if the time is in the appointment all blocks for that day do not appear
AND
( TIMESTAMP('2013-01-23 08:00:00')  
    NOT IN  (SELECT TIMESTAMP( start_time) FROM appointments )
)
*/

提案されたアプローチはありますか?

4

1 に答える 1

0

コメントアウトされた部分は、常に true または false に評価されます。したがって、すべての行を除外するか、行をまったく除外します。' TIMESTAMP('2013-01-23 08:00:00')' を、予定表のタイムスタンプに置き換える必要があります。たぶん、start_date と time_start に基づいてタイムスタンプを作成しますか?

于 2013-01-23T05:35:18.773 に答える