对于给定的表
1st column=producer
2nd column=type
A a
A a
A a
A b
B c
B c
B c
我想计算非重复组的数量。输出应该等于A=2 B=1
。
我不知道如何做到这一点:(
对于给定的表
1st column=producer
2nd column=type
A a
A a
A a
A b
B c
B c
B c
我想计算非重复组的数量。输出应该等于A=2 B=1
。
我不知道如何做到这一点:(
只需使用count()
:
select producer, count(distinct type)
from yourtable
group by producer
尝试这个:
select producer, count(distinct type) from table group by producer
这样的事情应该可以解决问题:
SELECT producer, COUNT(DISTINCT type)
FROM YOUR_TABLE
GROUP BY producer
这应该会给你类似的结果:
producer COUNT(DISTINCT type)
-------- --------------------
A 2
B 1
SELECT producer, COUNT(producer)
FROM table
GROUP BY producer, type