[mw_shl_code=sql,true]DROP TABLE IF EXISTS `user_chase`;
CREATE TABLE `user_chase` (
`cur_page` varchar(10) DEFAULT NULL,
`last_page` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of user_chase
-- ----------------------------
INSERT INTO `user_chase` VALUES ('A', null);
INSERT INTO `user_chase` VALUES ('C', 'A');
INSERT INTO `user_chase` VALUES ('E', 'C');
INSERT INTO `user_chase` VALUES ('D', 'E');
INSERT INTO `user_chase` VALUES ('Q', 'D');
INSERT INTO `user_chase` VALUES ('E', 'Q');
[/mw_shl_code]
[mw_shl_code=sql,true]SELECT
group_concat(b.last_page SEPARATOR '->')
FROM
nyd_cof.user_chase a
right join nyd_cof.user_chase b
on a.cur_page=b.last_page
where b.last_page is not null [/mw_shl_code]
结果 A->C->E->D->Q->E
貌似跟递归没关系,是典型的关联查询而已 |