这条SQL语句怎么写?
表名: TableName
字段:
UserID year month shuju TF
1 2007 4 5 1
2 2007 6 6.2 0
5 2006 6 2 1
1 2006 7 3 1
2 2007 7 42 0
2 2007 5 4 1
1 2007 5 2.2 1
3 2007 6 5 0
要求:把每个UserID取出TF为1,日期Year,Month最大的数数据shuju出来.
每个用户最多有一条.
结果要象这样.
UserID year month shuju TF
1 2007 5 2.2 1
2 2007 5 4 1
5 2006 6 2 1
------解决方案--------------------create table tb(UserID int,[year] varchar(10),[month] varchar(10),shuju decimal(18,2),TF int)
insert into tb values(1, '2007 ', '4 ', 5 , 1)
insert into tb values(2, '2007 ', '6 ', 6.2, 0 )
insert into tb values(5, '2006 ', '6 ', 2 , 1)
insert into tb values(1, '2006 ', '7 ', 3 , 1)
insert into tb values(2, '2007 ', '7 ', 42 , 0)
insert into tb values(2, '2007 ', '5