繁体   English   中英

ROW_NUMBER替代SQL Server 2000

[英]ROW_NUMBER Alternative for SQL Server 2000

现在我在SQL Server 2008的程序中使用ROW_NUMBER(),如下所示:

WITH cars as(SELECT carid,mileage,retailprice,imageurl,model,year, 
             Zips.Distance AS Miles, Manufacturers.mfgName as Make,
             dealers.companyname as companyname, CASE @sortby 
WHEN 'D' THEN ROW_NUMBER() OVER (ORDER BY  Manufacturers.mfgName) 
WHEN 'P' THEN ROW_NUMBER() OVER (ORDER BY retailprice) 
WHEN 'M' THEN ROW_NUMBER() OVER (ORDER BY mileage) 
END as 'rownum'
FROM usedcars INNER JOIN #TempZips Zips ON Zips.ZipCode =usedcars.loczip
left join Manufacturers on Manufacturers.mfgid=usedcars.mfgid 
left join dealers on dealers.dealerid = usedcars.dealerid 
where usedcars.active=1 and usedcars.dealerid=@dealerid)
select @totalrecords as totalrec,*  from cars 
where rownum between @skip and  @take

在SQL2000中是否有相同的功能? (直到SQL2005才引入ROW_NUMBER)。

您可以使用标识列创建临时表,并将数据插入其中。

然后使用临时表。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM