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