ROW_NUMBER() OVER的使用

该例子来自csdn论坛,看完这个例子就明白这个函数的用法了

select   * ,row_number()  over ( order   by  productname)  as  rownumber
from  products
-- 上面是正确的,然后我想的是从这个结果集在取10-20之间的数据,然后我书写如下:
select   * ,row_number()  over ( order   by  productname)  as  rownumber
from  products
where  rownumber  between   10   and   20
-- 这样报错.然后又找资料看,找不个例子.然后我照那个例子改进
select *   from
(
select   * ,row_number()  over ( order   by  productname)  as  rownumber
from  products)
as   temp
where  rownumber  between   10   and   20
-- 这样就对了.

 


 

你可能感兴趣的:(row_number())