0

我创建了 Mysql 函数,它给出结果整数或 NULL。它适用于所有值。如果在简单查询中使用此函数,它也可以按预期工作,如下查询:

select distinct(hsd.hotel_id) 
from hotel_season_detail hsd 
where '2019-04-26' BETWEEN hsd.season_fromdate and hsd.season_todate and hsd.stop_sale >'2019-04-26' and getHotelMarkupManagementId(hsd.id,'AFG') is NOT NULL

getHotelMarkupManagementId()是用户定义的mysql函数。如上查询返回酒店表中已存在的两个酒店 ID。

但是当这个查询添加为子查询时

select * from hotel_service 
where id in 
(select distinct(hsd.hotel_id) 
from hotel_season_detail hsd where '2019-04-26' BETWEEN hsd.season_fromdate and hsd.season_todate and hsd.stop_sale >'2019-04-26' and getHotelMarkupManagementId(hsd.id,'AFG') 
is NOT NULL)

它给出了错误的结果。它没有按预期工作。 select * from hotel_service where id in (125,126)给出结果,如果单独运行,子查询也会给出 id 125 和 126 作为结果。但是当作为子查询添加时它会失败

这种行为是否应该归因于mysql functioninIN子句?请建议。

4

1 回答 1

0

我认为在使用函数时这是 Mysql 中的一个问题,因为如果相同的第二个查询条件分为两个子查询,那么我的问题就解决了。

select * from hotel_service where id in (select distinct(hsd.hotel_id) from hotel_season_detail hsd where '2019-04-26' BETWEEN hsd.season_fromdate and hsd.season_todate and hsd.stop_sale >'2019-04-26') and id in (select distinct(hsd.hotel_id) from hotel_season_detail hsd where getHotelMarkupManagementId(hsd.id,'AFG') is not NULL)

我已经在不同的子查询中分离了 MySQL 函数,但是结合了相同的条件然后没有给出正确的结果。所以我建议使用与其他条件不同的mysql功能,如果条件是BETWEENOR>运算符。

于 2019-04-25T14:00:57.747 回答