本帖最后由 stneo1990 于 2012-04-25 18:10:20 编辑

解决方案 »

  1.   

    SELECT * FROM
    (SELECT `id`, `reply_id`, `name`, `content`, `time` FROM `reply` ORDER BY `time` DESC) tbl
    GROUP BY `reply_id`
    ORDER BY `time` DESC
      

  2.   

    参考下贴中的多种方法http://topic.csdn.net/u/20091231/16/2f268740-391e-40f2-a15e-f243b2c925ab.html
    [征集]分组取最大N条记录方法征集,及散分....
      

  3.   

    其中的一种解法如下。
    mysql> select * from reply;
    +----+----------+-------+---------+------+
    | id | reply_id | name  | content | time |
    +----+----------+-------+---------+------+
    |  1 |        1 | test1 | test1   |    1 |
    |  2 |        1 | test2 | test2   |    3 |
    |  3 |        2 | test3 | test3   |    2 |
    |  4 |        2 | test4 | test4   |    4 |
    |  5 |        3 | test5 | test5   |    1 |
    |  6 |        3 | test6 | test6   |    2 |
    |  7 |        3 | test7 | test7   |    5 |
    +----+----------+-------+---------+------+
    7 rows in set (0.00 sec)mysql> select * from reply r
        -> where not exists (select 1 from reply where reply_id=r.reply_id and time>r.time)
        -> order by time desc;
    +----+----------+-------+---------+------+
    | id | reply_id | name  | content | time |
    +----+----------+-------+---------+------+
    |  7 |        3 | test7 | test7   |    5 |
    |  4 |        2 | test4 | test4   |    4 |
    |  2 |        1 | test2 | test2   |    3 |
    +----+----------+-------+---------+------+
    3 rows in set (0.00 sec)mysql>
      

  4.   


    我想先order by time desc..再group by reply_id...
    group by 总是只保留第一个的吧?..