Skip to content

Instantly share code, notes, and snippets.

@kaminskypavel
Last active August 26, 2017 14:55
Show Gist options
  • Save kaminskypavel/36fc70fc7864537786fbdbb43e4a6196 to your computer and use it in GitHub Desktop.
Save kaminskypavel/36fc70fc7864537786fbdbb43e4a6196 to your computer and use it in GitHub Desktop.
mysql range bucketing values
SET @bucketSize = 100;
select
a.bucketCeil,
CONCAT(a.bucketCeil, ' - ', a.bucketCeil) as bucket,
count(*) as count
from (
select
floor(d.value/@bucketSize)*@bucketSize as bucketFloor,
floor(d.value/@bucketSize)*@bucketSize + @bucketSize as bucketCeil
from datapoints d) a
group by 1,2
order by 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment