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.
Do you mean this?
select car_make, count(*) from cars
group by car_makes
select car_made, count(*) as occurrences
from cars
group by car_made
order by occurrences desc, car_made
SELECT ... GROUP BY
http://dev.mysql.com/doc/refman/5.0/en/select.html
For example:SELECT CarName, COUNT(CarName) AS CarCount FROM tbl GROUP BY CarName