子句中WHERE的MySQL问题 [英] Mysql issue with WHERE in clause

查看:77
本文介绍了子句中WHERE的MySQL问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在mysql中的"where in"子句中遇到问题,我无法弄清楚出了什么问题. 所以我有两个桌子...

i'm having an issue with my "where in" clause in mysql and i can't figure out whats wrong. So I have two tables...

1)座位

(int)seat_id

(int) seat_id

2)寄存器

(int)register_id

(int) register_id

(varchar)seat_ids-以逗号分隔的席位,例如102,103,104

(varchar) seat_ids -- comma separated seats, for example 102,103,104

所以,我要获取匹配结果的查询是

So, my query to fetch the matching results is

SELECT * FROM Seats s, Registers r 
WHERE s.seat_id IN (r.seat_ids) 
GROUP BY s.seat_id

有人可以找出问题所在吗?谢谢,

Can someone figure out what's wrong ? Thanks,

推荐答案

IN要求列表是文字列表,而不是逗号分隔的字符串.为此使用FIND_IN_SET:

IN requires the list to be a literal list, not a comma-delimited string. Use FIND_IN_SET for that:

WHERE FIND_IN_SET(s.seat_id, r.seat_ids)

这篇关于子句中WHERE的MySQL问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆