简体   繁体   English

在mysql语句中循环遍历数组字段?

[英]Looping through array field in mysql statement?

I was given a database that is a little weird, but I am not able to change it. 我得到的数据库有点奇怪,但是我无法更改它。 There is a field that is set as an array but holds ids that I need to access in where clauses. 有一个字段设置为数组,但是包含我需要在where子句中访问的id。 Here is the field set up: 这是设置的字段:

TABLE: PROMOS
promo_id   |    contract_ids
-----------------------------
 1               23,34,54
 2               13,34,55
 3               20,30

I need to do an sql query to get all promo_ids where contract id = 34 我需要执行一个SQL查询以获取合同ID = 34的所有promo_ids

mysql_query("SELECT promo_id FROM Promos WHERE contract_ids = '34'

Is there a way to do this?? 有没有办法做到这一点?? Thanks for any help! 谢谢你的帮助!

SELECT promo_id FROM Promos 
WHERE FIND_IN_SET(34, contract_ids) > 0

See FIND_IN_SET doc 请参阅FIND_IN_SET文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM