逗号分隔的id数组获取名称的sql
SELECT
a.*,
p.contain_product,
p.contain_product_name,
c.product_name
FROM
landing_page a
LEFT JOIN (
SELECT
y.id,
y.contain_product,
(
GROUP_CONCAT(x.product_name)
) AS contain_product_name
FROM
product_group y,
product x
WHERE
FIND_IN_SET(x.id, y.contain_product) > 0
GROUP BY
y.id
) p ON a.shunt_products_group_id = p.id
LEFT JOIN xmkf_product c ON a.main_product_id = c.id
WHERE
a.is_deleted = 0
ORDER BY
a.id DESC
LIMIT 10
碰到的问题:
这条sql在mysql直接运行的时候是可以的,但是放到mybatis的xml文件里面就会报错,后查了半天,发现把 a.* 换成具体的字段就可以了,一直没搞懂为什么。