2011-01-20 30 views
0

私は2つのテーブルを持っています.1つはスケジュール、もう1つは特定のタイムブロックの利用可能な予定のリストです。私は日付に基づいて曜日の時間を取る(最初のクエリ)サブクエリの比較結果が返されない

select * from store_schedule where schedule_day = DATE_FORMAT('2011-01-17', '%a') 

上記の動作は問題ありません。

は、私は今、私は、2011年1月17日に同時に2件の予定を持っている私の場合は、日付と特定の時間

SELECT count(*) from store_appointment a, store_schedule b 
where a.store_schedule_id = b.id and apt_date = '2011-01-17' 

のために予定の総量を取得する2番目のクエリを持っています上記を使用して正確に返されます。

store_appointmentの同じstore_schedule_idをいくつの予定が共有できるのかを判断するために、store_scheduleにconcurrent_timesという列があります。以下は私の組み合わせた質問です。

select * from store_schedule where 
schedule_day = DATE_FORMAT('2011-01-17', '%a') AND 
(SELECT count(*) from store_appointment a, store_schedule b 
where a.store_schedule_id = b.id 
and apt_date = '2011-01-17') < concurrent_appointments 

このクエリは何らかの理由でゼロ結果を返します。誰でも私が間違っていることを見ることができますか?分割された各クエリは正常に動作します。

答えて

0

私は:(馬鹿だ。私は自分のクエリを読み違える。私はstore_scheduleに2番目のリンクを必要としません。以下は

正しいクエリが

select * 
from store_schedule aa 
where schedule_day = DATE_FORMAT('2011-01-17', '%a') 
    and ((select count(a.id) as countTotal 
     from store_appointment a 
     where a.store_schedule_id = aa.id 
      and apt_date = '2011-01-17') + 0) < concurrent_appointments 
です
関連する問題