我的表如下:
A B C D E F
张三 1 1 1 1 4 4
张三 1 1 1 1 4 6
李四 1 1 1 2 3 4
李四 1 1 1 2 3 8
李四 1 1 5 1 4 15
王五 1 1 1 1 4 4
王五 1 1 1 1 4 7
赵六 1 1 1 3 4 10
我想取表中每个人F字段里面最大的那条数据
理想结果如下:
张三 1 1 1 1 4 6
李四 1 1 5 1 4 15
王五 1 1 1 1 4 7
赵六 1 1 1 3 4 10
求SQL语句!
谢谢!
SQL code:
create table #TT1
(
A nvarchar(20),
B int,
C int,
D int,
E int,
F int,
G int
)
insert into #TT1 select '张三',1,1,1,1,4,4
insert into #TT1 select '张三',1,1,1,1,4,6
insert into #TT1 select '李四',1,1,1,1,4,4
insert into #TT1 select '李四',1,1,1,1,4,8
insert into #TT1 select '李四',1,1,1,1,4,15
insert into #TT1 select '王五',1,1,1,1,4,4
insert into #TT1 select '王五',1,1,1,1,4,7
insert into #TT1 select '赵六',1,1,1,3,4,10
select * from #TT1 T where not exists(select * from #TT1 where A=T.A and G>T.G)
A B C D E F G
-------------------- ----------- ----------- ----------- ----------- ----------- -----------
张三 1 1 1 1 4 6
李四 1 1 1 1 4 15
王五 1 1 1