Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Counting Instances of Unique Value in Field

Suppose you have a table in SQL:

Prices
------
13.99
14.00
52.00 
52.00 
52.00 
13.99

How would you count the amount of times a DIFFERENT field has been entered in? Therefore an example of such a count would output:

13.99 - 2 times. 
14.00 - 1 times. 
52.00 - 3 times.

OR perhaps:

3 (i.e. 13.99, 14.00, 52.00)

Can anyone advise? Cheers.

like image 995
Federer Avatar asked Dec 29 '22 13:12

Federer


1 Answers

How about:

SELECT Prices, COUNT(*) FROM TheTable GROUP BY Prices

Can't say I've tried it on MySql, but I'd expect it to work...

like image 97
Jon Skeet Avatar answered Jan 02 '23 09:01

Jon Skeet