22,181
社区成员




create table #EE
(
[Name] varchar(20),
sal int,
data int
)
insert into #EE select '张三',2000,2
union all select '张三',1900,3
union all select '李四',1500,2
union all select '李四',2100,3
select * from #EE E where not exists(select * from #EE where data=E.data and sal>E.sal)
Name sal data
-------------------- ----------- -----------
张三 2000 2
李四 2100 3
(2 行受影响)
select name,max(sal),data from tb group by name,data
select
name
sal
data
from tb t
where sal in(select max(sal) from tb where data=t.data)
select t.* from tab t where not exists(select 1 from tab where data=t.data and sal>t.sal)