回答編集履歴

3

推敲

2021/03/30 08:43

投稿

sazi
sazi

スコア25327

test CHANGED
@@ -10,17 +10,17 @@
10
10
 
11
11
  ), unit as (
12
12
 
13
- select max(rank) /4 as rank_unit from base
13
+ select trunc((max(rank) /4) + 0.9) as rank_unit from base
14
14
 
15
15
  )
16
16
 
17
- select rank / rank_unit as RANK_GROUP
17
+ select trunc(rank / rank_unit) as RANK_GROUP
18
18
 
19
19
  , AVG(SCORE), AVG(AGE)
20
20
 
21
21
  FROM base , unit
22
22
 
23
- GROUP BY rank / rank_unit
23
+ GROUP BY trunc(rank / rank_unit)
24
24
 
25
25
  ```
26
26
 

2

推敲

2021/03/30 08:43

投稿

sazi
sazi

スコア25327

test CHANGED
@@ -8,19 +8,19 @@
8
8
 
9
9
  from SCORE_TBL
10
10
 
11
- ), max_base as (
11
+ ), unit as (
12
12
 
13
- select max(rank) as max_rank from base
13
+ select max(rank) /4 as rank_unit from base
14
14
 
15
15
  )
16
16
 
17
- select rank / (max_rank / 4) as RANK_GROUP
17
+ select rank / rank_unit as RANK_GROUP
18
18
 
19
19
  , AVG(SCORE), AVG(AGE)
20
20
 
21
- FROM base , max_base
21
+ FROM base , unit
22
22
 
23
- GROUP BY rank / (max_rank / 4)
23
+ GROUP BY rank / rank_unit
24
24
 
25
25
  ```
26
26
 

1

追記

2021/03/30 08:37

投稿

sazi
sazi

スコア25327

test CHANGED
@@ -23,3 +23,5 @@
23
23
  GROUP BY rank / (max_rank / 4)
24
24
 
25
25
  ```
26
+
27
+ 件数が多いなら一時テーブル経由にした方が高速かもしれませんね。