使用ROW_NUMBER()方法查询结果集;语句如下:
select ROW_NUMBER() OVER(ORDER BY dbo.OrderOutProduct.ID) AS RowNumber, dbo.Order.ID,Telephone,AddressCity,Province, from dbo.Order inner join dbo.Order2on dbo.Order.ID=Order2IDinner join dbo.Order3on dbo.Order2.OrderID=dbo.Order3.Order3where Service=1 and RowNumber=1
但是出现了错误:列名 'RowNumber' 无效。
查到网上给的解释是:在sql里这个叫做,热名称,刚定的不能立马使用!要包一层查询!
修改为:
select * from(select ROW_NUMBER() OVER(ORDER BY dbo.OrderOutProduct.ID) AS RowNumber,dbo.Order.ID,Telephone,AddressCity,Province, from dbo.Order inner join dbo.Order2on dbo.Order.ID=Order2IDinner join dbo.Order3on dbo.Order2.OrderID=dbo.Order3.Order3where Service=1 )U where RowNumber=1
Technorati 标签: ROW_NUMBER(),列名 'RowNumber' 无效。