select phone,max(yxiaqi) from Recharge  where yxiaqi>getdate() group by phone

解决方案 »

  1.   


    要这个表的所有数据呢?不要只有phone 我缓存*好像不可以啊、
      

  2.   

    select *
    from Recharge   a
    where exists (select 1 from (select phone,max(yxiaqi)yxiaqi from Recharge  where yxiaqi>getdate() group by phone) b where a.phone=b.phone and a.yxiaqi =b.yxiaqi )
      

  3.   

    select *
    from 
    (
    select *,
       max(yxiaqi) over(partition by phone) as max_yxiaqi
    from Recharge   a
    where  yxiaqi>getdate()
    )t
    where yxiaqi = max_yxiaqi
      

  4.   


    能不能讲解下这个和楼上的有什么分别啊。都可以查询出来。都是对的。我好学习下。哦,这个就是用了 2005以后的,窗口函数,主要是简化sql语句,原理是一样的