例如,我有一个表,里面有产品及其价格。价格从1美元到15000美元不等。所以我想计算一下每个1000美元区间内的产品数量。基本上,我想知道有多少产品的成本高于0,低于1000美元,有多少产品的成本高于1000美元,低于2000美元。我知道如何对时间做同样的事情,但不知道结果应该是多少。
Interval Amount
1000 5
2000 4
3000 8
... ...
14000 6
15000 8发布于 2018-11-28 22:03:26
最简单的方法是使用一些数学方法进行聚合:
select ceil(amount / 1000) * 1000 as amt_group, count(*)
from t
group by amt_group
order by amt_group;发布于 2018-11-28 22:11:21
SELECT round(price,-3), count(*) FROM prices GROUP BY 1 ORDER BY 1;https://stackoverflow.com/questions/53520962
复制相似问题