首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

请问SQL语句,来大神

2012-09-17 
请教SQL语句,来大神userid reguid xftimexfpoint sypoint122012-09-07 14:56:2320122012-09-07 16:44:1420

请教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语句怎么写?

[解决办法]

SQL code
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*/ 

热点排行