有如下一个表,T1,
顾客   购买日期     购买商品     价格
甲     05-01-21      A           1.0
乙     05-12-01      B           2.0
甲     05-03-14      C           3.0
甲     05-06-01      A           1.0
丙     05-12-16      D           4.0
丙     05-09-10      C           3.0
丁     05-12-11      B           2.0怎样用SQL语句查询出每位顾客最近购买的日期,商品和价格,如上表查询后的结果是:
顾客   购买日期     购买商品     价格
甲     05-06-01      A           1.0
乙     05-12-01      B           2.0
丙     05-12-16      D           4.0
丁     05-12-11      B           2.0谢谢。

解决方案 »

  1.   

    select top1 * from 表 group by 顾客 order by 购买日期  desc
      

  2.   

    select * from (select * from t1  order by 购买日期  desc) group by 顾客
      

  3.   

    select * from (select * from t1(你的表名)  order by 购买日期  desc) group by 顾客
      

  4.   

    select * from.....group by 一个字段的形式是非法的。这个问题没这么简单。
      

  5.   

    have a tryselect ta.* from T1 ta
     where (ta.顾客|ta.购买日期) in (select max(顾客|购买日期) from T1 where 顾客=ta.顾客)
      

  6.   

    select ta.* from T1 ta
     where ta.购买日期 = (select max(购买日期) from T1 where 顾客=ta.顾客)
      

  7.   

    SELECT T1.顾客, T1.购买日期, 购买商品, 价格
    FROM T1, [SELECT 顾客, MAX(购买日期) AS LASTDATE FROM t1 GROUP BY 顾客]. AS A
    WHERE T1.顾客=A.顾客 AND T1.购买日期=A.LASTDATE;
      

  8.   

    把楼上代码中的 [] 改为 ():Select A.顾客,A.购买日期,A.购买商品,A.价格 
    From 表名 As A,(Select 顾客,Max(购买日期) As LastDate From 表名 Group By 购买日期) As B
    Where A.顾客=B.顾客 And A.购买日期=B.LastDate
      

  9.   


    select distinct 顾客,购买日期,购买商品,价格 from T1 orger by 购买日期 DESC
      

  10.   

    把楼上代码中的 [] 改为 ():Select A.顾客,A.购买日期,A.购买商品,A.价格 
    From 表名 As A,(Select 顾客,Max(购买日期) As LastDate From 表名 Group By 购买日期) As B
    Where A.顾客=B.顾客 And A.购买日期=B.LastDate的Group By 购买日期应该改为Group By 顾客
      

  11.   

    楼主,我认为可能需要用Compute by 语句.....
      

  12.   


    select 顾客,max(购买日期) from test11 group by 顾客不能得到顾客的顺序
      

  13.   

    楼主解决,请把SQL 语句写一下...,谢谢....
      

  14.   

    我试过了,faysky2() 的方法是可行的,不过在我的实际查询中出现一点点问题,就是如果顾客在同一天买多样的东西,购买日期是一样的,那么faysky2() 的方法就会出现重复的顾客记录,不过还是满足查询要求的,谢谢各位的帮忙。
      

  15.   

    哦,是of123()最先提出的,一时看错了,特别谢谢of123(), ^o^