How to count occurrences of a computed column in SQL?

In ms sql, I am trying to count the number of computed column.

With the usual classics do not worry:

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

But with computed column an ​​error message is displayed

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

Do you know if there is a way to do this?

+6
source share
1 answer

Use this ... you want to group by the same calculated expression to get a count grouped by this expression

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

All Articles