SELECT * FROM `open` WHERE id in (
SELECT DISTINCT CASE _id WHEN 0 THEN p0.id WHEN 1 THEN p1.id WHEN 2 THEN p2.id WHEN 3 THEN p3.id END as id FROM `open` p0
LEFT JOIN `open` p1 ON p1.id = p0.sj
LEFT JOIN `open` p2 ON p2.id = p1.sj
LEFT JOIN `open` p3 ON p3.id = p2.sj
CROSS JOIN( SELECT 0 as _id UNION ALL SELECT 1 UNION ALL SELECT 2 ) p
WHERE p0.openid='CC' ID DESC
);
网友评论