mysql 通过上级IDs查询所有上级名称

表结构是这样的


通过  0,1,2,3查询出相对应得名称

SELECT
	GROUP_CONCAT(t1.`name` ORDER BY t1.type)
FROM
	(
		SELECT
			b.`name`,
			b.type,
			'03826d9158c542cc9578042cdfd58a7b' AS iid
		FROM
			jx_resource_classification a
		LEFT JOIN jx_resource_model b ON a.model_id = b.id
		WHERE
			a.id IN (
				SELECT
					c.id
				FROM
					jx_resource_classification b
				LEFT JOIN jx_resource_classification c ON concat(',', b.up_id, ',') LIKE concat('%,', c.id, ',%')
				WHERE
					b.id = '03826d9158c542cc9578042cdfd58a7b'
			)
	) t1
GROUP BY
	t1.iid;

猜你喜欢

转载自blog.csdn.net/s1040342522/article/details/80830130