Nam Hao Nam Hao - 6 months ago 9
SQL Question

How to count total comment in a category not a topic

My database:

category (cat_id,cat_name)
topic (topic_id,cat_is)
comment(com_id,topic_is)


Now I want to count total comment in a category.

Answer
select cat_id, count(1) cnt 
     from category 
     join topic on cat_is = cat_id
     join comment on topic_is = topic_id
  group by cat_id