Mysql 子查询比较不返回结果

Mysql 子查询比较不返回结果,mysql,subquery,Mysql,Subquery,我有两张桌子,一张是时间表,另一张是特定时间段的可用约会列表。我根据日期优先查询获取一周中某一天的时间 select * from store_schedule where schedule_day = DATE_FORMAT('2011-01-17', '%a') 以上方法很好 我还有第二个查询,从中可以得到某个日期和特定时间的约会总数 SELECT count(*) from store_appointment a, store_schedule b where a.store_sche

我有两张桌子,一张是时间表,另一张是特定时间段的可用约会列表。我根据日期优先查询获取一周中某一天的时间

select * from store_schedule where schedule_day = DATE_FORMAT('2011-01-17', '%a')
以上方法很好

我还有第二个查询,从中可以得到某个日期和特定时间的约会总数

SELECT count(*) from store_appointment a, store_schedule b 
where a.store_schedule_id = b.id and apt_date = '2011-01-17'
就我而言,我现在在2011年1月17日同时有两次约会,使用上述信息准确返回

在我的门店预约中,我有一个名为concurrent_times的列,用于确定有多少约会可以共享门店预约中的相同门店预约id。下面是我的综合查询

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

由于某种原因,此查询返回零结果。有人能看出我做错了什么吗?每个被分解的查询都很好。

我是个白痴:。我误解了我自己的疑问。我不需要第二个链接来存储计划

下面是正确的查询

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