Using Count to find the number of occurrences

后端 未结 4 975
太阳男子
太阳男子 2020-11-29 06:26

Let\'s say I have a table with the following values.

Ford
Ford
Ford
Honda
Chevy
Honda
Honda
Chevy

So I want to construct the following outp

4条回答
  •  清歌不尽
    2020-11-29 06:52

    Hope this works for you!!

    SELECT car_brand, COUNT(id) from cars
    GROUP BY car_brand
    

    COUNT(id) with InnoDB is faster than COUNT(*) because InnoDB doesn't cache the row count.

提交回复
热议问题