回答編集履歴

3

体裁

2021/09/18 07:35

投稿

takanaweb5
takanaweb5

スコア359

test CHANGED
@@ -80,7 +80,7 @@
80
80
 
81
81
  , date
82
82
 
83
- , case when first_value(id) over(partition by user_id order by date, id) = id
83
+ , case when first_value(id) over(partition by user_id order by date) = id
84
84
 
85
85
  then 1 else 0 end as 初登場
86
86
 

2

スキーマ定義を他の人の回答にあわせる

2021/09/18 07:35

投稿

takanaweb5
takanaweb5

スコア359

test CHANGED
@@ -14,13 +14,13 @@
14
14
 
15
15
  , user_id
16
16
 
17
- , date_
17
+ , date
18
18
 
19
- , case when first_value(id) over(partition by user_id order by date_, id) = id
19
+ , case when first_value(id) over(partition by user_id order by date, id) = id
20
20
 
21
21
  then 1 else 0 end as 初登場
22
22
 
23
- from テーブル名
23
+ from tx
24
24
 
25
25
  order by id
26
26
 
@@ -32,7 +32,7 @@
32
32
 
33
33
 
34
34
 
35
- | id | user_id | date_ | 初登場 |
35
+ | id | user_id | date | 初登場 |
36
36
 
37
37
  | :--- | :------ | :--------- | :----- |
38
38
 
@@ -70,7 +70,7 @@
70
70
 
71
71
  ```sql
72
72
 
73
- with sub1(user_id, date_, 初登場) as
73
+ with sub1 as
74
74
 
75
75
  (
76
76
 
@@ -78,21 +78,21 @@
78
78
 
79
79
  user_id
80
80
 
81
- , date_
81
+ , date
82
82
 
83
- , case when first_value(id) over(partition by user_id order by date_, id) = id
83
+ , case when first_value(id) over(partition by user_id order by date, id) = id
84
84
 
85
- then 1 else 0 end
85
+ then 1 else 0 end as 初登場
86
86
 
87
- from テーブル名
87
+ from tx
88
88
 
89
- ), sub2(date_, 日別UU, 通算UU) as
89
+ ), sub2 as
90
90
 
91
91
  (
92
92
 
93
93
  select
94
94
 
95
- date_
95
+ date
96
96
 
97
97
  , count(distinct user_id) as 日別UU
98
98
 
@@ -100,7 +100,7 @@
100
100
 
101
101
  from sub1
102
102
 
103
- group by date_
103
+ group by date
104
104
 
105
105
  )
106
106
 
@@ -108,14 +108,14 @@
108
108
 
109
109
  select
110
110
 
111
- date_
111
+ date
112
112
 
113
113
  , 日別UU
114
114
 
115
- , sum(通算UU) over(order by date_) as 通算UU
115
+ , sum(通算UU) over(order by date) as 通算UU
116
116
 
117
117
  from sub2
118
118
 
119
- order by date_
119
+ order by date
120
120
 
121
121
  ```

1

要約変更

2021/09/18 07:32

投稿

takanaweb5
takanaweb5

スコア359

test CHANGED
@@ -1,4 +1,4 @@
1
- joinを使わずにwindow関数のみで実現する方法を紹介します。
1
+ 結合や相関サブクエリを使わずにwindow関数のみで実現する方法を紹介します。
2
2
 
3
3
 
4
4