我有一张表tmp
。
查询:
select * from tmp
我希望以下列方式得到结果:
customer_id | subscriber_id | totalSubscribers
320 | 433 | 3
320 | 434 | 3
你能告诉我如何实现这个目标吗?
答案 0 :(得分:2)
以下是您提问的解决方案
SELECT customer_id , subscriber_id , count(*) AS totalSubscribers
FROM `tmp` GROUP BY 1,2
或
SELECT customer_id , subscriber_id , count(*) AS totalSubscribers
FROM `tmp` GROUP BY customer_id , subscriber_id
答案 1 :(得分:0)
以下是答案
SELECT customer_id , subscriber_id , count(*) as [TOTAL]
FROM tmp
GROUP BY customer_id , subscriber_id