select sp_name, office, comm
from sperson
where (office,comm) in (select office, min(comm) from sperson group by office);
这适用于Oracle和MySQL。
答案 0 :(得分:1)
您需要具有 correlation 的子查询,并且SQL Server将支持语法:
select sp.*
from sperson sp
where comm = (select min(sp1.comm)
from sperson sp1
where sp1.office = sp.office
);
但是,这也可以通过row_number()
/ dense_rank()
函数来实现:
select top (1) with ties sp.*
from sperson sp
order by row_number() over (partition by office order by comm);