sybase iq分组排序取前N名
sybase iq分组排序取前N名
营业部客户资产前5客户语句
Sql代码 www.zzzyk.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