Mysql查询树状结构sql:

SELECT
	id,
	code,
	name,
	parent_id
FROM
	(
		SELECT
			t1.id,
			t1.parent_id,
			t1.name,
			t1.code,

		IF (
			find_in_set(parent_id, @pids) > 0,
			@pids := concat(@pids, ',', id),
			0
		) AS ischild
		FROM
			(
				SELECT
					id,
					parent_id,
					name,
					code
				FROM
					表名
				WHERE
					isdelete = '0'
			) t1,
			(
				SELECT
					@pids := (
						SELECT
							id
						FROM
							表名
						WHERE
							code = '10045'
					)
			) t2
	) t3
WHERE
	ischild != '0'
OR code = '10045'