日期:2014-05-16  浏览次数:20971 次

单一记录的查询问题
wage表,用来记录所有员工的所有历史工资和最新工资记录(包括先前所有旧的和现在新的),现在要查询一条关于某个员工的最新工资记录(只要一条记录),该如何实现

如wage表中有记录
ID 工号 姓名 职称类别 岗位工资 任职年限 套改年限 薪级 薪级工资 工资 标志 年度
1 101 AAA 副高级 930 8 33 32 767 1697 2007
258 101 AAA 副高级 930 9 34 33 799 1729 2008
259 101 AAA 副高级 930 10 35 34 834 1764 2009

现在只要能select出
259 101 AAA 副高级 930 10 35 34 834 1764 2009
这一条记录,怎么办?(ID是自动编码,到底是多少,我不知道的)

------解决方案--------------------
1
select * from tt a where id=(select top 1 id from tt
where a.工号=工号 order by id desc)
2
select a.* from tt a inner join
(select 工号,max(id) as ma from tt group by 工号) b
on a.id=id

------解决方案--------------------
3.

Select * From wage Where ID In (Select Max(ID) From wage Group By 工号)

4.

Select * From wage A Where Not Exists(Select ID From wage Where 工号 = A.工号 And ID > A.ID)


我的异常网推荐解决方案:软件开发者薪资,http://www.aiyiweb.com/other/1391128.html