Skip to content

Instantly share code, notes, and snippets.

@puriketu99
Last active August 29, 2015 14:11
Show Gist options
  • Save puriketu99/5ffabcade6d8331d308a to your computer and use it in GitHub Desktop.
Save puriketu99/5ffabcade6d8331d308a to your computer and use it in GitHub Desktop.
sqlで度数分布表、ヒストグラムを書くイディオム ref: http://qiita.com/puriketu99/items/1b9a1537dbb2d4028bf8
select
turn_id,
sum(case when life >= 0 and life <= 5 then 1 else 0 end) as life_from0to5,
sum(case when life > 5 and life <= 10 then 1 else 0 end) as life_from5to10,
sum(case when life > 10 and life <= 15 then 1 else 0 end) as life_from10to15,
sum(case when life > 15 and life <= 20 then 1 else 0 end) as life_from15to20,
sum(case when life > 20 and life <= 25 then 1 else 0 end) as life_from20to25,
sum(case when life > 25 and life <= 30 then 1 else 0 end) as life_from25to30
from log_life
group by turn_id
order by turn_id desc
limit 24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment