1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
create table t1 (
pk int primary key,
a int,
b int
);
create table t2 (
pk int primary key,
a int,
b int,
c char(10)
);
insert into t2 values
( 1, 0, 1, 'one'),
( 2, 0, 2, 'two'),
( 3, 0, 3, 'three'),
( 4, 1, 1, 'one'),
( 5, 1, 1, 'two'),
( 6, 1, 2, 'three');
# First try some invalid queries.
select std(c) over (order by a)
from t2;
std(c) over (order by a)
0
0
0
0
0
0
# Empty frame.
select std(b) over (order by a rows between 2 following and 1 following) as exp
from t2;
exp
NULL
NULL
NULL
NULL
NULL
NULL
select std(b) over (order by a range between 2 following and 1 following) as exp
from t2;
exp
NULL
NULL
NULL
NULL
NULL
NULL
select std(b) over (order by a rows between 1 preceding and 2 preceding) as exp
from t2;
exp
NULL
NULL
NULL
NULL
NULL
NULL
select std(b) over (order by a range between 1 preceding and 2 preceding) as exp
from t2;
exp
NULL
NULL
NULL
NULL
NULL
NULL
select std(b) over (order by a rows between 1 following and 0 following) as exp
from t2;
exp
NULL
NULL
NULL
NULL
NULL
NULL
select std(b) over (order by a range between 1 following and 0 following) as exp
from t2;
exp
NULL
NULL
NULL
NULL
NULL
NULL
select std(b) over (order by a rows between 1 following and 0 preceding) as exp
from t2;
exp
NULL
NULL
NULL
NULL
NULL
NULL
select std(b) over (order by a range between 1 following and 0 preceding) as exp
from t2;
exp
NULL
NULL
NULL
NULL
NULL
NULL
select std(b) over (order by a rows between 0 following and 1 preceding) as exp
from t2;
exp
NULL
NULL
NULL
NULL
NULL
NULL
select std(b) over (order by a range between 0 following and 1 preceding) as exp
from t2;
exp
NULL
NULL
NULL
NULL
NULL
NULL
# 1 row frame.
select std(b) over (order by a rows between current row and current row) as exp
from t2;
exp
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
select std(b) over (order by a rows between 0 preceding and current row) as exp
from t2;
exp
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
select std(b) over (order by a rows between 0 preceding and 0 preceding) as exp
from t2;
exp
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
select std(b) over (order by a rows between 0 preceding and 0 following) as exp
from t2;
exp
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
select std(b) over (order by a rows between 0 following and 0 preceding) as exp from t2;
exp
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
select std(b) over (order by a rows between 0 following and current row) as exp
from t2;
ERROR HY000: Unacceptable combination of window frame bound specifications
select std(b) over (order by a rows between current row and 0 following) as exp
from t2;
exp
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
# Only peers frame.
select a, b, std(b) over (order by a range between 0 preceding and 0 preceding) as exp
from t2;
a b exp
0 1 0.8165
0 2 0.8165
0 3 0.8165
1 1 0.4714
1 1 0.4714
1 2 0.4714
select a, b, std(b) over (order by a range between 0 preceding and current row) as exp
from t2;
a b exp
0 1 0.8165
0 2 0.8165
0 3 0.8165
1 1 0.4714
1 1 0.4714
1 2 0.4714
select a, b, std(b) over (order by a range between current row and 0 preceding) as exp
from t2;
ERROR HY000: Unacceptable combination of window frame bound specifications
select a, b, std(b) over (order by a range between current row and 0 following) as exp
from t2;
a b exp
0 1 0.8165
0 2 0.8165
0 3 0.8165
1 1 0.4714
1 1 0.4714
1 2 0.4714
select a, b, std(b) over (order by a range between 0 following and 0 following) as exp
from t2;
a b exp
0 1 0.8165
0 2 0.8165
0 3 0.8165
1 1 0.4714
1 1 0.4714
1 2 0.4714
# 2 rows frame.
select pk, a, b, std(b) over (order by a, b, pk rows between 1 preceding and current row) as exp
from t2;
pk a b exp
1 0 1 0.0000
2 0 2 0.5000
3 0 3 0.5000
4 1 1 1.0000
5 1 1 0.0000
6 1 2 0.5000
select pk, a, b, std(b) over (order by a, b, pk rows between 1 preceding and 0 preceding) as exp
from t2;
pk a b exp
1 0 1 0.0000
2 0 2 0.5000
3 0 3 0.5000
4 1 1 1.0000
5 1 1 0.0000
6 1 2 0.5000
select pk, a, b, std(b) over (order by a, b, pk rows between current row and 1 following) as exp
from t2;
pk a b exp
1 0 1 0.5000
2 0 2 0.5000
3 0 3 1.0000
4 1 1 0.0000
5 1 1 0.5000
6 1 2 0.0000
select pk, a, b, std(b) over (order by a, b, pk rows between 0 following and 1 following) as exp
from t2;
pk a b exp
1 0 1 0.5000
2 0 2 0.5000
3 0 3 1.0000
4 1 1 0.0000
5 1 1 0.5000
6 1 2 0.0000
# 2 peers frame.
select pk, a, b, std(b) over (order by a range between 1 preceding and current row) as exp
from t2;
pk a b exp
1 0 1 0.8165
2 0 2 0.8165
3 0 3 0.8165
4 1 1 0.7454
5 1 1 0.7454
6 1 2 0.7454
select pk, a, b, std(b) over (order by a range between 1 preceding and 0 preceding) as exp
from t2;
pk a b exp
1 0 1 0.8165
2 0 2 0.8165
3 0 3 0.8165
4 1 1 0.7454
5 1 1 0.7454
6 1 2 0.7454
select pk, a, b, std(b) over (order by a range between current row and 1 following) as exp
from t2;
pk a b exp
1 0 1 0.7454
2 0 2 0.7454
3 0 3 0.7454
4 1 1 0.4714
5 1 1 0.4714
6 1 2 0.4714
select pk, a, b, std(b) over (order by a range between 0 following and 1 following) as exp
from t2;
pk a b exp
1 0 1 0.7454
2 0 2 0.7454
3 0 3 0.7454
4 1 1 0.4714
5 1 1 0.4714
6 1 2 0.4714
drop table t1;
drop table t2;
|