查询返回空行

时间:2017-03-25 08:29:15

标签: mysql

我有一个查询返回所有字段的空行,而不是返回0行。我认为Min是问题,一旦我删除它,它开始返回0行。如何在不改变查询结果的情况下修复它?

select *,min(STR_TO_DATE(concat(slot_date, ' ' , sec_to_time(from_time)),  '%Y-%m-%d %H:%i')) next_available_slot 
from  appt_available_slots 
where country_id = 1 
and   city_id = 1 
and   spec_id= 1 
and company_id = ifnull (NULLIF(2, 0), company_id) 
and slot_date ='2017-04-02' 
order by from_time ; 

1 个答案:

答案 0 :(得分:0)

要获得一行,您应该使用LIMIT 1,而不是MIN()列表中的SELECT

select *, STR_TO_DATE(concat(slot_date, ' ' , sec_to_time(from_time)),  '%Y-%m-%d %H:%i') next_available_slot
from  appt_available_slots
where country_id = 1 
and   city_id = 1 
and   spec_id= 1 
and company_id = ifnull (NULLIF(2, 0), company_id) 
and slot_date ='2017-04-02' 
order by from_time
limit 1