3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

BigQueryでスコアの上位x%ラインをNTILEで算出する

Posted at

概要

スコアの上位x%ラインを算出して欲しいという要求があった。NTILEでやったのでメモ。

SQL

例として上位10%とする。
NTILE(10)の1のscoreの最小値をとる。


WITH ntiled as (
    SELECT score, NTILE(10) OVER (ORDER BY score desc) as ntile FROM table_name 
)

SELECT MIN(score) FROM ntiled WHERE ntile = 1
3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?