2016-04-28 727 views
6

在ms sql中,我嘗試計算計算列的出現次數。如何統計SQL中計算列的出現次數?

與正常的經典之作,無後顧之憂:

SELECT ID, COUNT(*) 
    FROM User 
    GROUP BY ID 

但隨着計算列它顯示一個錯誤

SELECT CONVERT(INT, (ID * PI())) AS TOTO, COUNT(*) 
FROM User 
GROUP BY TOTO 

你知道,如果有一種方法可以做到這一點?

+1

'SELECT'處理分組計數BY' –

回答

11

使用該...你要組由同一個計算表達式獲得通過表達組後`

SELECT CONVERT(INT, (ID * PI())) AS TOTO, COUNT(*) 
FROM User 
GROUP BY CONVERT(INT, (ID * PI()))