Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to count the number of rows being grouped in group by?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

simple group by and count? :

select email,topic_id, count(*) 
from tablename
group by email,topic_id
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading