本帖最后由 ghostxyz0 于 2011-08-06 16:21:17 编辑

解决方案 »

  1.   

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

  2.   

    其中一种解法如下。select * from test a where not exists (select 1 from test where uid=a.uid and dateline<a.dateline)
      

  3.   

    select *
    from tb A
    where not exits (select 1 from tb A.uid=uid and A.id>id)
      

  4.   

    mysql> select * from test;
    +----+------------------+------+-------+------------+
    | Id | orderid          | uid  | money | dateline   |
    +----+------------------+------+-------+------------+
    |  1 | 9581fc1156b6cc24 |    1 |  6.00 | 1312459705 |
    |  2 | a65a60abe8bc2a63 |    2 | 23.00 | 1312462748 |
    |  3 | a19bedcf22ee3aad |    1 | 15.00 | 1312476597 |
    |  4 | a5cf44b4985f8a57 |    2 |  9.00 | 1312537818 |
    |  5 | 6a8ed9409f5a9673 |    4 | 14.00 | 1312615274 |
    |  6 | 4fd8a33f35c4dd4d |    1 | 19.00 | 1312581043 |
    |  7 | 1de9ef6bc4f39555 |    3 | 29.00 | 1312606256 |
    |  8 | e5beacd54cd7df99 |    4 | 12.00 | 1312559431 |
    |  9 | a639da6dce717a1c |    3 | 10.00 | 1312618895 |
    | 10 | 616a8a4249c0a7cb |    2 | 18.00 | 1312622509 |
    +----+------------------+------+-------+------------+--首次-------------------------------------------------------
    mysql> select *
        -> from test t
        -> where not exists(select 1 from test where t.uid=uid and t.Id>Id);
    +----+------------------+------+-------+------------+
    | Id | orderid          | uid  | money | dateline   |
    +----+------------------+------+-------+------------+
    |  1 | 9581fc1156b6cc24 |    1 |  6.00 | 1312459705 |
    |  2 | a65a60abe8bc2a63 |    2 | 23.00 | 1312462748 |
    |  5 | 6a8ed9409f5a9673 |    4 | 14.00 | 1312615274 |
    |  7 | 1de9ef6bc4f39555 |    3 | 29.00 | 1312606256 |
    +----+------------------+------+-------+------------+
    4 rows in set (0.00 sec)---最近一次-------------------------------------------------------
    mysql> select *
        -> from test t
        -> where not exists(select 1 from test where t.uid=uid and t.Id<Id);
    +----+------------------+------+-------+------------+
    | Id | orderid          | uid  | money | dateline   |
    +----+------------------+------+-------+------------+
    |  6 | 4fd8a33f35c4dd4d |    1 | 19.00 | 1312581043 |
    |  8 | e5beacd54cd7df99 |    4 | 12.00 | 1312559431 |
    |  9 | a639da6dce717a1c |    3 | 10.00 | 1312618895 |
    | 10 | 616a8a4249c0a7cb |    2 | 18.00 | 1312622509 |
    +----+------------------+------+-------+------------+
    4 rows in set (0.00 sec)
      

  5.   

    一种方法按照自增id判断
    code
    select id,uid,money,from_unixtime(dateline) from test order by id desc;
    +----+------+-------+-------------------------+
    | id | uid  | money | from_unixtime(dateline) |
    +----+------+-------+-------------------------+
    | 10 |    2 | 18.00 | 2011-08-06 17:21:49     |
    |  9 |    3 | 10.00 | 2011-08-06 16:21:35     |
    |  8 |    4 | 12.00 | 2011-08-05 23:50:31     |
    |  7 |    3 | 29.00 | 2011-08-06 12:50:56     |
    |  6 |    1 | 19.00 | 2011-08-06 05:50:43     |
    |  5 |    4 | 14.00 | 2011-08-06 15:21:14     |
    |  4 |    2 |  9.00 | 2011-08-05 17:50:18     |
    |  3 |    1 | 15.00 | 2011-08-05 00:49:57     |
    |  2 |    2 | 23.00 | 2011-08-04 20:59:08     |
    |  1 |    1 |  6.00 | 2011-08-04 20:08:25     |
    +----+------+-------+-------------------------+二种方法按照时间排序
    code
    select id,uid,money,from_unixtime(dateline) from test order by dateline desc;
    +----+------+-------+-------------------------+
    | id | uid  | money | from_unixtime(dateline) |
    +----+------+-------+-------------------------+
    | 10 |    2 | 18.00 | 2011-08-06 17:21:49     |
    |  9 |    3 | 10.00 | 2011-08-06 16:21:35     |
    |  5 |    4 | 14.00 | 2011-08-06 15:21:14     |
    |  7 |    3 | 29.00 | 2011-08-06 12:50:56     |
    |  6 |    1 | 19.00 | 2011-08-06 05:50:43     |
    |  8 |    4 | 12.00 | 2011-08-05 23:50:31     |
    |  4 |    2 |  9.00 | 2011-08-05 17:50:18     |
    |  3 |    1 | 15.00 | 2011-08-05 00:49:57     |
    |  2 |    2 | 23.00 | 2011-08-04 20:59:08     |
    |  1 |    1 |  6.00 | 2011-08-04 20:08:25     |
    +----+------+-------+-------------------------+呵,不知道是否对你有帮助
      

  6.   

    除了 ACMAIN_CHM 写的, 其它都是错的.不过方法已经掌握了