我在sql server上有这个表
cstomer |No_Nota
CUS000 | 98342
CUS000 | 98343
CUS000 | 98343
CUS001 | 98355
CUS001 | 98355
我想计算每个客户的频率。对于相似数量的no_nota,该值为1.
我想要这样的结果:
cstomer |Frequent
CUS000 | 2
CUS001 | 1
答案 0 :(得分:3)
您想要列no_nota
的明确计数,这就是您应该选择的内容......
select customer, count(distinct no_nota) as frequent
from my_table
group by customer
答案 1 :(得分:0)
您想要计算选择查询的结果:
SELECT COUNT(expression)
FROM tables
WHERE predicates;
示例:
SELECT COUNT(No_Nota) FROM your_table WHERE No_Nota > 0;
答案 2 :(得分:0)
听起来你只想要一个group by语句来计算所有个人客户的数量。类似的东西:
SELECT cstomer, SUM(1) as Frequent FROM table GROUP BY cstomer, No_Nota