In ms sql, I try to count occurence of a computed column .
With a normal classic, no worries:
SELECT ID, COUNT(*)
FROM User
GROUP BY ID
But with calculated column it display an Error
SELECT CONVERT(INT, (ID * PI())) AS TOTO, COUNT(*)
FROM User
GROUP BY TOTO
Do you know if there is a way to do it?
COUNT(ID) as NumberOfOccurance:- Counting the number of occurrence of a ID. group by – It is necessary in aggregate function like 'count()' otherwise it will give error. having (COUNT(ID)>1) -Select those rows which count of ID value is greater than 1, that's why it shows '0' and '1'.
Use this...you want to group by the same computed expression to get the count grouped by that expression
SELECT CONVERT(INT, (ID * PI())) AS TOTO, COUNT(*)
FROM User
GROUP BY CONVERT(INT, (ID * PI()))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With