gpt4 book ai didi

MySql: FIND_IN_SET 不能正常工作

转载 作者:太空宇宙 更新时间:2023-11-03 10:59:26 24 4
gpt4 key购买 nike

我有一个带有字符串参数的存储过程。此参数是分开的,如 '759,760,761'。在 where 子句中,我想像这样使用它。

...AND REL.CountyId IN (FIND_IN_SET(REL.CountyId, '759,760,761') > 0) 

但没有返回数据,但有 759 县 ID 的行。如果我删除这个条款,数据就会来。

这是我所有的sql代码:

    SELECT 
REL.RealEstateListingId,
(SELECT
ImageUrl
FROM
realestateimage
WHERE
IsMainImage = 1 AND Status = 1
AND RealEstateListingId = REL.RealEstateListingId) AS ImageUrl,

REL.ListingNumber,
REL.Caption,
REL.M2,
REL.RoomCount,
/*CONCAT((SELECT Name FROM City WHERE CityId IN (SELECT CityId FROM County WHERE CountyId = REL.CountyId)),'/', (SELECT Name FROM County WHERE CountyId = REL.CountyId)) AS Region,*/
REL.Price,
REL.Creation,
REL.CountyId
FROM
realestatelisting AS REL
INNER JOIN
User AS U ON U.UserId = REL.CreatedBy
/*INNER JOIN realestatefilterrelation AS RFR ON RFR.RealEstateId = REL.RealEstateListingId*/
WHERE REL.Price BETWEEN 0 AND 1000000
AND CAST(REL.M2 AS SIGNED) BETWEEN 0 AND 1000
/*AND REL.CountyId IN (FIND_IN_SET(REL.CountyId, '759') > 0)

/*AND RFR.FilterContentId IN(FIND_IN_SET(RFR.FilterContentId, filterIds) > 0)*/
ORDER BY REL.Creation;

最佳答案

试试这个方法:

...AND FIND_IN_SET(REL.CountyId, '759,760,761') > 0

在查询中可能看起来像:

...
WHERE REL.Price BETWEEN 0 AND 1000000
AND CAST(REL.M2 AS SIGNED) BETWEEN 0 AND 1000
AND FIND_IN_SET(REL.CountyId, '759') > 0
AND FIND_IN_SET(RFR.FilterContentId, filterIds) > 0
ORDER BY REL.Creation;

FIND_IN_SET(str,strlist)

Returns a value in the range of 1 to N if the string str is in the string list strlist consisting of N substrings.

Returns 0 if str is not in strlist or if strlist is the empty string.

...因此,大于 0 的数字表示“找到”。

在这种情况下,带有 in 的部分是无用的,除非您对列表中的特定位置感兴趣。

关于MySql: FIND_IN_SET 不能正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17102969/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com