summaryrefslogtreecommitdiffstats
path: root/mysql-test/main/win_std.test
blob: c2186747f42c4957b172cc061c7d95134f917808 (plain)
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
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');

--disable_warnings
--echo # First try some invalid queries.
select std(c) over (order by a)
from t2;
--enable_warnings

--echo # Empty frame.
select std(b) over (order by a rows between 2 following and 1 following) as exp
from t2;

select std(b) over (order by a range between 2 following and 1 following) as exp
from t2;

select std(b) over (order by a rows between 1 preceding and 2 preceding) as exp
from t2;

select std(b) over (order by a range between 1 preceding and 2 preceding) as exp
from t2;

select std(b) over (order by a rows between 1 following and 0 following) as exp
from t2;

select std(b) over (order by a range between 1 following and 0 following) as exp
from t2;

select std(b) over (order by a rows between 1 following and 0 preceding) as exp
from t2;

select std(b) over (order by a range between 1 following and 0 preceding) as exp
from t2;

select std(b) over (order by a rows between 0 following and 1 preceding) as exp
from t2;

select std(b) over (order by a range between 0 following and 1 preceding) as exp
from t2;

--echo # 1 row frame.
select std(b) over (order by a rows between current row and current row) as exp
from t2;

select std(b) over (order by a rows between 0 preceding and current row) as exp
from t2;

select std(b) over (order by a rows between 0 preceding and 0 preceding) as exp
from t2;

select std(b) over (order by a rows between 0 preceding and 0 following) as exp
from t2;

select std(b) over (order by a rows between 0 following and 0 preceding) as exp from t2;

--error ER_BAD_COMBINATION_OF_WINDOW_FRAME_BOUND_SPECS
select std(b) over (order by a rows between 0 following and current row) as exp
from t2;

select std(b) over (order by a rows between current row and 0 following) as exp
from t2;

--echo # Only peers frame.
--sorted_result
select a, b, std(b) over (order by a range between 0 preceding and 0 preceding) as exp
from t2;

--sorted_result
select a, b, std(b) over (order by a range between 0 preceding and current row) as exp
from t2;

--error ER_BAD_COMBINATION_OF_WINDOW_FRAME_BOUND_SPECS
select a, b, std(b) over (order by a range between current row and 0 preceding) as exp
from t2;

--sorted_result
select a, b, std(b) over (order by a range between current row and 0 following) as exp
from t2;

--sorted_result
select a, b, std(b) over (order by a range between 0 following and 0 following) as exp
from t2;

--echo # 2 rows frame.

--sorted_result
select pk, a, b, std(b) over (order by a, b, pk rows between 1 preceding and current row) as exp
from t2;

--sorted_result
select pk, a, b, std(b) over (order by a, b, pk rows between 1 preceding and 0 preceding) as exp
from t2;

--sorted_result
select pk, a, b, std(b) over (order by a, b, pk rows between current row and 1 following) as exp
from t2;

--sorted_result
select pk, a, b, std(b) over (order by a, b, pk rows between 0 following and 1 following) as exp
from t2;

--echo # 2 peers frame.

--sorted_result
select pk, a, b, std(b) over (order by a range between 1 preceding and current row) as exp
from t2;

--sorted_result
select pk, a, b, std(b) over (order by a range between 1 preceding and 0 preceding) as exp
from t2;

--sorted_result
select pk, a, b, std(b) over (order by a range between current row and 1 following) as exp
from t2;

--sorted_result
select pk, a, b, std(b) over (order by a range between 0 following and 1 following) as exp
from t2;

drop table t1;
drop table t2;