Let’s say I have a table with columns as email, topic_id. One email can corresponds to one topic_id multiple times. I want to apply group by based on email and topic_id. But I’m unble to count how many rows are grouped together.
Example.
email topic_id
abc@gmail.com 1
abc@gmail.com 1
abc@gmail.com 1
abc@gmail.com 2
xyz@gmail.com 1
xyz@gmail.com 1
xyz@gmail.com 1
The output should give :
email topic_id count
abc@gmail.com 1 3
abc@gmail.com 2 1
xyz@gmail.com 1 3
>Solution :
simple group by and count? :
select email,topic_id, count(*)
from tablename
group by email,topic_id