2
SELECT `e`.`id`, `e`.`title`, `e`.`description`, `e`.`event_time`,(SELECT GROUP_CONCAT( name SEPARATOR " | " ) 
FROM `ar_products` 
WHERE id IN **(e.products)** AS products FROM events e;

我在带有列名产品的事件表中有逗号分隔的产品 ID 列表。如果我使用值 54,33,23.. 它显示正确的值,如产品列表[product1 | product2 | ..]

当我在 IN CLAUSE 中直接使用列名时,它不起作用。

4

1 回答 1

20

It sound like you are looking for FIND_IN_SET http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_find-in-set. Change the WHERE clause to:

WHERE FIND_IN_SET(id, e.products) AS products FROM events e;
于 2013-07-10T12:36:31.503 回答