I have a list of data. I want to know which value appears in the data the most often, and the percentage of it appearing. I am having trouble writing the sql statement with mysql.
| SitePoint Sponsor |



I have a list of data. I want to know which value appears in the data the most often, and the percentage of it appearing. I am having trouble writing the sql statement with mysql.





Could you please post the table(s) structure.



KeyCol | DataColOriginally Posted by westmich
----------------
A | 1
B | 2
C | 1
D | 1
E | 5
F | 1
I want to return that DataCol's most used value is 1, and that it is in 67% of the rows.



You can see the table structure is very simple, but I cannot figure out the way to do this.





Try -
Select Count(DataCol) as ColumnCount, KeyCol
From Table
Group By KeyCol
It should give you something like -
25 A
13 B
10 C
With a little server-side code you should be able to calculate percentages.
Bookmarks