select *
from
(
select a.s_nb,
b.*,
(row_number() over(order by a.s_nb) - 1) / @page_size as rownum
from
(
select SUM(nb) as s_nb,colthno
from cmd_xjjx_sale
where outdate<='20140223' and outdate>='20140216' and endprice>0
group by colthno
)a
inner join BI数据仓库.dbo.BI_colthno_kind b
on a.colthno=b.colthno