简体   繁体   English

如何计算SQL中计算列的出现次数?

[英]How to count occurrences of a computed column in SQL?

In ms sql, I try to count occurence of a computed column . 在ms sql中,我尝试计算计算列的出现次数。

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? 你知道有没有办法做到这一点?

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()))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM