回答編集履歴
3
修正
answer
CHANGED
@@ -6,7 +6,11 @@
|
|
6
6
|
, max(case when rank=2 then card_type end) as card_type_2
|
7
7
|
, max(case when rank=2 then created_at end) as created_at_2
|
8
8
|
from (
|
9
|
+
select *
|
10
|
+
, greatest(
|
11
|
+
main_rank
|
9
|
-
|
12
|
+
, case when main_rank>=2 and sub_rank>=2 then 3 else sub_rank end
|
13
|
+
) Rank
|
10
14
|
from (
|
11
15
|
select id, card_type, cnt, created_at
|
12
16
|
, (
|
2
修正
answer
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
, max(case when rank=2 then card_type end) as card_type_2
|
7
7
|
, max(case when rank=2 then created_at end) as created_at_2
|
8
8
|
from (
|
9
|
-
select *,
|
9
|
+
select *, main_rank * 10 + sub_rank as rank
|
10
10
|
from (
|
11
11
|
select id, card_type, cnt, created_at
|
12
12
|
, (
|
1
推敲
answer
CHANGED
@@ -55,4 +55,5 @@
|
|
55
55
|
) step2
|
56
56
|
where rank <= 2
|
57
57
|
group by id
|
58
|
+
order by id
|
58
59
|
```
|