Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 550
ATMathew Avatar asked Oct 04 '11 22:10

ATMathew


People also ask

How do I count the number of occurrences of a number in Excel?

Use the COUNTIF function to count how many times a particular value appears in a range of cells. For more information, see COUNTIF function.

How do you count the number of occurrences in a column?

In Excel, I can tell you some simple formulas to quickly count the occurrences of a word in a column. Select a cell next to the list you want to count the occurrence of a word, and then type this formula =COUNTIF(A2:A12,"Judy") into it, then press Enter, and you can get the number of appearances of this word.

How do you count occurrences of items in a list Excel?

Use the =Countif function to count the number of times each unique entry appears in the original list.


2 Answers

Do you mean this?

select car_make, count(*) from cars group by car_makes 
like image 136
Mosty Mostacho Avatar answered Oct 01 '22 18:10

Mosty Mostacho


select car_made, count(*) as occurrences from cars group by car_made order by occurrences desc, car_made 
like image 33
ajreal Avatar answered Oct 01 '22 19:10

ajreal