Table
ID   Price   Date
3    1       2002-10-3
3    2       2002-11-2
3    4       2003-3-6
4    3       2002-9-5
4    2       2003-2-20
5    1       2002-10-8
6    1       2002-11-4
现在需要取出每个ID1 的 Date 为最大的所有行。怎么写??即:
ID    Price   Date
3     4       2003-3-6
4     2       2003-2-20
5     1       2002-10-8
6     1       2002-11-4

解决方案 »

  1.   

    select distinct  id  Price   Date
    from table
    where date >=all(
                  select max(date)
                  from table)
      

  2.   

    select distinct  id  Price   Date
    from table  order by data desc//就是让你的结果按递减的顺序排列
    ok,就会显示你上面的结果
      

  3.   

    没有想到更好的,这个给你:
    select a.* from store a,
    (select sid, max(scount) as scount from store group by sid) b
    where a.sid = b.sid and a.scount = b.scount order by a.sid
      

  4.   

    ID Date Table分别替换我语句中sid, scount, store就OK了
      

  5.   

    SELECT Table.id, Table.Price, Table.date
    FROM Table,(SELECT Table.id, Max(Table.date) AS MDate
    FROM Table GROUP BY Table.id) as b
    WHERE (((Table.date)=b.MDate));