现有表a,有3个字段,
id, no,  time
1   1001   2010-10-09 14:51:00
2   1002   2010-10-09 14:52:00
3   1001   2010-10-09 14:53:00
4   1003   2010-10-09 14:54:00
5   1003   2010-10-09 14:55:00
6   1003   2010-10-09 14:56:00
7   1003   2010-10-09 14:57:00
8   1004   2010-10-09 14:59:00我想得到的结果是
3   1001   2010-10-09 14:53:00
2   1002   2010-10-09 14:52:00
7   1003   2010-10-09 14:57:00
8   1004   2010-10-09 14:59:00就是no字段唯一,但是time最新的那一组数据。求SQL 语句,谢谢了!!

解决方案 »

  1.   

    select id, no, time from table order by id ,time
      

  2.   

    $sql = 'select * from a group by no order by time desc';
      

  3.   


    这个语句是先group然后对group的结果按time排序。
    我想要的是对于相同的项按time排序,然后再group。
      

  4.   

    喔你要NO 优先排列   ,可以这样试试 。select id, no, time from table group by no order by no,time 
      

  5.   

    select id, no, time from table group by no,time,id order by no,time
      

  6.   


    SELECT * FROM (SELECT * FROM a ORDER BY time DESC) AS t GROUP BY t.no