0

I have a table with column 'Price' and would need to get the most frequent value. What would be the eeasiest way?

John V
  • 4,589
  • 10
  • 36
  • 62

2 Answers2

2

One option would be something like

SELECT price
  FROM (SELECT price, rank() over (order by cnt desc) rnk
          FROM (SELECT price, count(*) cnt
                  FROM your_table
                 GROUP BY price))
 WHERE rnk = 1

If there are two (or more) prices that occur equally as often, both will be returned by this query. If you want to guarantee a single row, you'll need to tell us how you want to handle ties.

Justin Cave
  • 221,607
  • 22
  • 353
  • 373
0

My algorithm is as follows:

  1. Step one: make distinct selection as a collection;
  2. Step two: foreach item in distinct collection count the items found in the original collection as diffcollection;
  3. Step three: select max from diffcollection.
Andries
  • 1,517
  • 10
  • 29