2013-10-16 72 views
0

我有這方面的工作查詢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計算作爲一個字段,以便能夠在現場在哪裏使用它? NTile4 = 70是基準,我只需要看基準。

謝謝!

回答

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; 
+0

快到了,但我收到此錯誤信息消息102,級別15,狀態1,行13 附近有語法錯誤 ';'。 – Herman

+0

哦,對不起我的錯誤,我錯過了刪除分隔符;經過分組後。編輯過的查詢請立即嘗試。 – Deepshikha

+0

然後它給了我: Msg 156,Level 15,State 1,Line 15 關鍵字'where'附近的語法不正確。 – Herman