gpt4 book ai didi

php - IN返回空的MySQL查询

转载 作者:行者123 更新时间:2023-11-29 00:05:34 24 4
gpt4 key购买 nike

我在运行 IN 键返回空的查询时遇到了问题。这是我的查询:

 SELECT * FROM `sc_miscellaneous` where discount_for=4 AND stud_id IN (1,2) AND status=1

此查询返回正确的结果。但是如果我使用 IN (2,3)IN (2) 意味着零结果。例如。

SELECT * FROM `sc_miscellaneous` where discount_for=4 AND stud_id IN (2,3) AND status=1

sc_miscellaneous:

ID Miscellaneous misc_amount discount discount_for class stud_id               status
1 5 200 2 4 1 1,2,3,4,5,6, 1
7,8,9,10,11,
12,13,14,15,16,
17,18,19

2 6 500 2 4 1 1,2,3,4,5,6,7 1

提前致谢。

最佳答案

已更新

使用以下查询

SELECT * FROM `sc_miscellaneous` 
WHERE stud_id LIKE '%,2,%' OR stud_id LIKE '%,3,%'
OR stud_id LIKE '2,%,' OR stud_id LIKE '3,%'
OR stud_id LIKE '%,2' OR stud_id LIKE '%,3'

因为您有 varchar 逗号分隔列表。

检查

1) 如果该唯一编号在逗号分隔列表之间,

2)或者如果是在开始

3) 或者如果它在末尾。

关于php - IN返回空的MySQL查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27653715/

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