我从之前的问题编辑过...我努力了但是我只通过主要帖子ID返回结果....不使用最后一条评论ID(预期)
所以我想从底部到顶部。不是反之亦然。
帖子
id_post | post | comment_of
25 main post 0
26 comment 1st level 25
27 comment 2nd level 26
28 another post 0
29 comment not related 14
30 comment 3rd level 27
31 comment not related 13
查询
SELECT id_post,
post,
comment_of
FROM (SELECT * FROM posts
ORDER BY comment_of, id_post) posts_sorted,
(SELECT @pv := '25') initialisation
WHERE find_in_set(comment_of, @pv)
AND length(@pv := concat(@pv, ',', id_post))
OR id_post=@pv
结果
id_post | post | comment_of
25 main post 0
26 comment 1st level 25
27 comment 2nd level 26
30 comment 3rd level 27
工作小提琴http://sqlfiddle.com/#!9/c07667/2
我想通过上一条评论获得结果 ,而不是主要帖子....在这种情况下,我想通过选择30
获得相同的结果(最后评论) )。反之亦然