MySQL从一栏中计算不同的值 [英] MySQL Count distinct values from one column
本文介绍了MySQL从一栏中计算不同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含三列的表:
I have a table having three columns:
A B C
1 2 2
2 2 2
3 1 1
4 1 2
我想要计算C等于2但B值不同的那些值的计数
I want the count of those values which have C equal to 2 but with distinct values of B
所以在这种情况下,对于C = 2,计数= 2(B = 2和B = 1)
So in this case for C = 2, count = 2 (B=2 and B=1)
我使用了以下命令:
Select count(*) from mytable where C=2 group by (B)
但它会产生:
count(*)
3
我尝试使用"distinct",但不能用于从一列中选择
I have tried using "distinct" but it can't be use to select from one column
推荐答案
您尝试过
SELECT COUNT(DISTINCT B) FROM mytable WHERE C = 2;
这篇关于MySQL从一栏中计算不同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文