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 )
select * from ( select *, max(yxiaqi) over(partition by phone) as max_yxiaqi from Recharge a where yxiaqi>getdate() )t where yxiaqi = max_yxiaqi
要这个表的所有数据呢?不要只有phone 我缓存*好像不可以啊、
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 )
from
(
select *,
max(yxiaqi) over(partition by phone) as max_yxiaqi
from Recharge a
where yxiaqi>getdate()
)t
where yxiaqi = max_yxiaqi
能不能讲解下这个和楼上的有什么分别啊。都可以查询出来。都是对的。我好学习下。哦,这个就是用了 2005以后的,窗口函数,主要是简化sql语句,原理是一样的