sybase iq分組排序取前N名
營業部客戶資產前5客戶語句
Sql代碼 www.2cto.com
select
*
from
(
select
*
from #ADO_TEMP
)t1 where exists
(
select count(1) from #ADO_TEMP t2 where t1.營業部=t2.營業部 and t1.總資產>t2.總資產
having count(1)<5
) order by t1.營業部,t1.總資產 desc
;
oracle可以用rank()函數,sybaseiq也有rank(),但是我那機器版本不支持
rank() over(partition by t2.org_full_name order by t1.總資產 desc) pm