VIEW中的ROW_Count

时间:2013-08-20 06:22:29

标签: sql-server view

我可以在SQL Server中运行此查询:

 SELECT "HIRING PIPE REQ NUMBER", 
       ROW_NUMBER() 
         OVER ( 
           PARTITION BY "HIRING PIPE REQ NUMBER" 
           ORDER BY "HIRING PIPE REQ NUMBER") RowNumber 
FROM   DBO.TALENTDELIVERY_REQ_3FACTS 

但是,当我将下面的代码放在VIEW中时,它失败了。

    SELECT "HIRING PIPE REQ NUMBER", 
       ROW_NUMBER() 
         OVER ( 
           PARTITION BY "HIRING PIPE REQ NUMBER" 
           ORDER BY "HIRING PIPE REQ NUMBER")AS RowNumber 
FROM   (SELECT * 
        FROM   DBO.TALENTDELIVERY_REQ_3FACTS) 

为什么在VIEW中失败?
如何在VIEW中编写上述内容?

1 个答案:

答案 0 :(得分:1)

试试这个 -

CREATE VIEW dbo.vw_view1 AS     

    SELECT  [Hiring Pipe Req Number]
        ,   ROW_NUMBER() OVER (
                PARTITION BY [Hiring Pipe Req Number] 
                ORDER BY 1/0
            ) AS RowNumber
    FROM
    (
        SELECT *
        FROM dbo.TalentDelivery_Req_3Facts
    ) t