sqlmysqlgroup-bycount

Using Count to find the number of occurrences


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 output.

Ford   3
Honda  3
Chevy  2

It just takes the count of each element in the column.

I'm having an issue listing the unique columns.

Can anyone tell me how to do this?

I've messed around with UNIQUE and DISTINCT, but I'm not able to get the list of values on the left.


Solution

  • Do you mean this?

    select car_make, count(*) from cars
    group by car_makes