How do I count the number of occurences of a value in a MySQL table?

For example, if you have some similar records that you want to calculate in your MySQL database, you can run a SQL query to report on that information.

hostname OS Vendor
host01 Linux Dell
host02 Windows HP
host03 Linux IBM

mysql> select OS, count(*) as Num from host_info group by OS order by Num desc;
| OS | Num |
| Linux | 2 |
| Windows | 1 |

SELECT name,COUNT(*) as count FROM tablename GROUP BY name ORDER BY count DESC;

Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

To Top