sql求助,

chaowenxuan 2009-04-07 01:48:21
有如下表,table
name sal data
张三 2000 2
张三 1900 3
李四 1500 2
李四 2100 3

如何查询出每个月的最高工资。

name sal data
张三 2000 2
李四 2100 3




...全文
42 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
chaowenxuan 2009-04-07
  • 打赏
  • 举报
回复
十分感谢
ws_hgo 2009-04-07
  • 打赏
  • 举报
回复
人齐结贴
ws_hgo 2009-04-07
  • 打赏
  • 举报
回复
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 行受影响)
ws_hgo 2009-04-07
  • 打赏
  • 举报
回复

select name,max(sal),data from tb group by name,data 
百年树人 2009-04-07
  • 打赏
  • 举报
回复
select 
name
sal
data
from tb t
where sal in(select max(sal) from tb where data=t.data)
chaowenxuan 2009-04-07
  • 打赏
  • 举报
回复
select 1 指的是什么,
子陌红尘 2009-04-07
  • 打赏
  • 举报
回复
select t.* from tab t where not exists(select 1 from tab where data=t.data and sal>t.sal)

22,211

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧