Skip to content

Instantly share code, notes, and snippets.

@yssymmt
Created April 17, 2022 15:16
Show Gist options
  • Save yssymmt/a2ae2f891c43dd8fe2cf0e9072deeb5c to your computer and use it in GitHub Desktop.
Save yssymmt/a2ae2f891c43dd8fe2cf0e9072deeb5c to your computer and use it in GitHub Desktop.
select
width_bucket(col1, 最小値, 最大値, 階級数) as 階級,
min(col1) as 下限値,
max(col1) as 上限値,
count(*) as 件数
from (
select
col1,
min(col1) over() as 最小値,
max(col1) over() as 最大値,
ceiling((log(count(*) over()) / log(2))+1) as 階級数
from データベース名.テーブル名
) a1
group by 1
order by 1
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment