在sql视图中添加一个sequence Generator列,并根据序列执行过滤条件

时间:2015-09-15 12:40:35

标签: sql sql-server database sql-server-2008

我有一个名为' test'的sql视图就像,

  Name  Profession
  Mak   Manager
  San   Doctor

我需要添加一个序列列,使其看起来像,

  Srno   Name  Profession
    1     Mak   Manager
    2     San   Doctor

现在我需要根据序列SrNo查询

    Select  * from  test where SrNo between 1 and  5.

但这不起作用

1 个答案:

答案 0 :(得分:1)

试试这个

With CTE1 AS(
SELECT row_number() over (order by (select NULL)) as Sr_no,Name,Profession
from table_Name)
Select * From cte1 where Sr_No between 1 and  5.