27,579
社区成员
发帖
与我相关
我的任务
分享
--用max()函数的方法:
select 字段A ,max(字段B) from table group by 字段A
--不用max()函数的方法:
select * from table as a where not exists(select * from table where a.字段A=字段A and a.字段B<字段B)
declare @table table (字段A varchar(1),字段B int)
insert into @table
select 'a',0 union all
select 'a',12 union all
select 'b',11 union all
select 'b',10
select 字段A,max(字段B) as 字段B from @table group by 字段A
/*
字段A 字段B
---- -----------
a 12
b 11
*/
select 字段A ,max(字段B) from table group by 字段A
select * from tb t where 字段B=(select max(字段B) from tb where 字段A=t.字段A)