更新时间:2022-11-21 11:29:28
要在列中存储逗号分隔的值是错误的设计,您应该查看 数据库规范化 ,并通过将所有相关的type_head存储在联结表中来规范化您的结构,但是如果您无法更改结构,那么在mysql中您可以使用 FIND_IN_SET() 并加入您的c_head表,如果它在提供的集合中找到值,它将选择记录,IN()对集合或逗号分隔列表中的值不起作用
To store comma separated values in column is bad design you should look at Database Normalization and do normalize your structure by storing all related type_head in a junction table,but if you can't change structure so in mysql you can use FIND_IN_SET() and join your c_head table,it will select records if it find the value in provided set,IN() will not work for values in set or in comma separated list
SELECT i.id, i.item
FROM c_item i
JOIN c_head h ON(FIND_IN_SET(i.type_head,h.no) > 0)
WHERE h.id = 9
ORDER BY i.item