假设我有一个表格,其中包含电子邮件、topic_id 等列。一封邮件可以多次对应一个topic_id。我想根据电子邮件和 topic_id 申请分组。但我无法计算有多少行组合在一起。例子。
email topic_id
[email protected] 1
[email protected] 1
[email protected] 1
[email protected] 2
[email protected] 1
[email protected] 1
[email protected] 1
输出应给出:
email topic_id count
[email protected] 1 3
[email protected] 2 1
[email protected] 1 3
简单的分组和计数?:
select email,topic_id, count(*)
from tablename
group by email,topic_id
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句