如何查找表中多列的数量
create table foo (key1 int(11), key2 int(11) ..)
我想在单个查询中从 foo 中选择 select count() for key1 和 count() for key2,这可能吗?
最佳答案
如果你想计算不同的值,你可以这样做:
select count(distinct key1), count(distinct key2)
from foo;
如果您想按值计数,可以使用union all
:
select key1, count(*)
from foo
group by key1
union all
select key2, count(*)
from foo
group by key2;
关于mysql - 如何查找多列的计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27496684/