关于sqlserver中ROW_NUMBER()中OVER里Order By字段的问题
如果用ROW_NUMBER() OVER (ORDER BY Column ASC)会产生这样一个怪问题,
那就是当Column有重复数据时,同一条sql语句每次查询出来的数据会不一样,比如Column是date类型,我有一万条数据的这个字段的值是2012-05-30,那么我查询其中10条数据时,每次执行结果都不一样,这个问题应该怎么解决,并且对性能影响不大。
;WITH ViewList ( [row], PartNumber, SerialNumber,EndUserName,PurchaseDate,DealerName,EndUserProvince,EndUserCity,EndUserAddress,LotNumber,DeliveryDate,ReceiptDate) AS (SELECT ROW_NUMBER() OVER (ORDER BY ReceiptDate ASC) [row],PartNumber, SerialNumber,EndUserName,PurchaseDate,DealerName,EndUserProvince,EndUserCity,EndUserAddress,LotNumber,DeliveryDate,ReceiptDate FROM [dbo].[ScannerWarranty]) SELECT [row], PartNumber, SerialNumber,EndUserName,PurchaseDate,DealerName,EndUserProvince,EndUserCity,EndUserAddress,LotNumber,DeliveryDate,ReceiptDate FROM ViewList WHERE [row] BETWEEN 91 AND 100
;WITH ViewList ( [row], PartNumber, SerialNumber,EndUserName,PurchaseDate,DealerName,EndUserProvince,EndUserCity,EndUserAddress,LotNumber,DeliveryDate,ReceiptDate) AS (SELECT ROW_NUMBER() OVER (ORDER BY GETDATE() ) [row],PartNumber, SerialNumber,EndUserName,PurchaseDate,DealerName,EndUserProvince,EndUserCity,EndUserAddress,LotNumber,DeliveryDate,ReceiptDate FROM [dbo].[ScannerWarranty]) SELECT [row], PartNumber, SerialNumber,EndUserName,PurchaseDate,DealerName,EndUserProvince,EndUserCity,EndUserAddress,LotNumber,DeliveryDate,ReceiptDate FROM ViewList WHERE [row] BETWEEN 91 AND 100
[解决办法]
ORDER BY ReceiptDate,GETDATE()
[解决办法]