SQL: How to get the count of each distinct value in a column?

前端 未结 1 709
醉酒成梦
醉酒成梦 2020-11-28 18:45

I have a SQL table called \"posts\" that looks like this:

id | category
-----------------------
1  | 3
2  | 1
3  | 4
4  | 2
5  | 1
6  | 1
7  | 2
相关标签:
1条回答
  • 2020-11-28 19:00
    SELECT
      category,
      COUNT(*) AS `num`
    FROM
      posts
    GROUP BY
      category
    
    0 讨论(0)
提交回复
热议问题