查找最常见的数字范围 [英] Finding most common range of numbers
本文介绍了查找最常见的数字范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个保存价格的表格,其背后的想法是让用户建议他们认为合理的价格,例如;范围
I have a table that holds prices, the idea behind it is to have users suggest prices they think are reasonable for a good,example; range
推荐答案
可以将价格除以区间大小,然后使用FLOOR()
得到区间的开头:>
You can divide the price by the range size, and then use FLOOR()
to get the beginning of the range:
SELECT 1500*FLOOR(price/1500) AS price_base, COUNT(*) AS count
FROM yourTable
GROUP BY price_base
ORDER BY count DESC
例如,price_base = 3000
包含从 3000
到 4499
的所有价格,而 price_base = 4500
包含从 4500
到 5999
的所有价格.
For example, price_base = 3000
contains all prices from 3000
to 4499
, while price_base = 4500
contains all prices from 4500
to 5999
.
这篇关于查找最常见的数字范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文