日期:2014-05-17 浏览次数:20497 次
create table xz
(员工id int,部门id int,薪水 int)
insert into xz
select 1,1,2 union all
select 2,1,1 union all
select 3,2,5 union all
select 4,2,6 union all
select 5,3,3
select a.员工id,a.部门id,a.薪水
from xz a
inner join
(select 部门id,max(薪水) '薪水'
from xz group by 部门id) b on a.部门id=b.部门id and a.薪水=b.薪水
order by a.部门id
/*
员工id 部门id 薪水
----------- ----------- -----------
1 1 2
4 2 6
5 3 3
(3 row(s) affected)
*/
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-10-22 11:23:26
-- Version:
-- &n