请教SQL语句,来大神
userid reguid xftime xfpoint sypoint
1 2 2012-09-07 14:56:23 2 0
1 2 2012-09-07 16:44:14 2 0
1 3 2012-09-08 15:56:23 2 0
这个是表结构
我想达到的目的是通过userid 查询 reguid 的最新一条记录 最后的效果如下
1 2 2012-09-07 16:44:14 2 0
1 3 2012-09-08 15:56:23 2 0
SQL语句怎么写?
[解决办法]
declare @T table (userid int,reguid int,xftime datetime,xfpoint int,sypoint int)insert into @Tselect 1,2,'2012-09-07 14:56:23',2,0 union allselect 1,2,'2012-09-07 16:44:14',2,0 union allselect 1,3,'2012-09-08 15:56:23',2,0select * from @T twhere xftime=(select max(xftime) from @T where reguid=t.reguid)and userid=1/*userid reguid xftime xfpoint sypoint----------- ----------- ----------------------- ----------- -----------1 2 2012-09-07 16:44:14.000 2 01 3 2012-09-08 15:56:23.000 2 0*/