How can I find the most frequent value in a given column in an SQL table?
For example, for this table it should return
two
since it is the most frequent value:one
two
two
three
Ans:
SELECT ColName, COUNT(ColName) AS count
FROM Table
GROUP BY ColName
ORDER BY count DESC
LIMIT 1;
Note: Increase 1 if you want to see the N
most common values of the column.
No comments:
Post a Comment