第1个回答 2013-12-20
select a.categoryId,sort+a.n-b.num+1 from
(
select ROW_NUMBER() over(order by categoryId) n,sort,categoryId from product ) a
inner join (
select categoryId,min(n) num from (
select ROW_NUMBER() over(order by categoryId) n,sort,categoryId from product )a
group by categoryId
)b on a.categoryId=b.categoryId
order by categoryId