SQL:仅显示百分位数

时间:2013-10-16 11:22:23

标签: sql

我有这个有效的查询

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 Field中使用它? NTile4 = 70是基准,我只需要看基准。

谢谢!

1 个答案:

答案 0 :(得分: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;