Search code examples
mysqlsqldatabasemode

How to calculate mode from database


I have county name, year and price. I am trying to calculate mode however I am not sure how, I am looking for a simplest possible command.

SELECT COUNT(Price_€)AS Frequency FROM `sales20102015` WHERE Date_of_Sale LIKE '%2010%' AND County = 'Monaghan'

this will show a number of total rows in the database...

any ideas? thanks


Solution

  • This query will select the single most common price, and the number of occurences:

    SELECT Price_€, COUNT(Price_€) FROM `sales20102015` 
    WHERE Date_of_Sale LIKE '%2010%' AND County = 'Monaghan'
    GROUP BY Price_€
    ORDER BY COUNT(Price_€) DESC
    LIMIT 1;