0

我有这个工作查询

SELECT MIN([DealerCode])   
    ,[201309]   
    ,RowNum = Row_Number() OVER(Order By [201309])   
    ,Rnk = RANK() OVER(ORDER BY [201309])   
    ,DenseRnk = DENSE_RANK() OVER(ORDER BY [201309])   
    ,NTile4  = NTILE(100) OVER(ORDER BY [201309])   
    ,BM = RANK() OVER(ORDER BY [201309])*0.7 

FROM [SA_Sew].[dbo].[Sew_YTD_Composite$]   
where Ratio_ID = 'fi02u' AND DealerCode like '%VW%'    
GROUP BY [201309];

我如何能够将 NTile4 计算作为一个字段,以便能够在 Where 字段中使用它?NTile4 = 70 是基准,我只需要查看基准。

谢谢!

4

1 回答 1

2

写为:

select * from 
(
SELECT MIN([DealerCode]) as MinDealerCode   
    ,[201309]   
    ,RowNum = Row_Number() OVER(Order By [201309])   
    ,Rnk = RANK() OVER(ORDER BY [201309])   
    ,DenseRnk = DENSE_RANK() OVER(ORDER BY [201309])   
    ,NTile4  = NTILE(100) OVER(ORDER BY [201309])   
    ,BM = RANK() OVER(ORDER BY [201309])*0.7 

FROM [SA_Sew].[dbo].[Sew_YTD_Composite$]   
where Ratio_ID = 'fi02u' AND DealerCode like '%VW%'    
GROUP BY [201309]
) as T
where NTile4  = 70;
于 2013-10-16T11:26:46.820 回答