日期:2014-05-17 浏览次数:20766 次
select top 1 userid from A inner join B on A.userid=B.userid where sex=1 order by rank union all select top 1 userid from A inner join B on A.userid=B.userid where sex=2 order by rank
------解决方案--------------------
select userid from b
(
select sex,min(rank) as rank from
(
select * from a , b
where a.userid=b.userid
) c
group by sex
) d
where b.rank =d.rank