Skip to content

Commit a37f24b

Browse files
committed
Add min/max test cases for window functions
1 parent 14690c7 commit a37f24b

File tree

2 files changed

+146
-0
lines changed

2 files changed

+146
-0
lines changed

mysql-test/r/win_min_max.result

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
create table t1 (
2+
pk int primary key,
3+
a int,
4+
b int,
5+
c real
6+
);
7+
insert into t1 values
8+
(101 , 0, 10, 1.1),
9+
(102 , 0, 10, 2.1),
10+
(103 , 1, 10, 3.1),
11+
(104 , 1, 10, 4.1),
12+
(108 , 2, 10, 5.1),
13+
(105 , 2, 20, 6.1),
14+
(106 , 2, 20, 7.1),
15+
(107 , 2, 20, 8.15),
16+
(109 , 4, 20, 9.15),
17+
(110 , 4, 20, 10.15),
18+
(111 , 5, NULL, 11.15),
19+
(112 , 5, 1, 12.25),
20+
(113 , 5, NULL, 13.35),
21+
(114 , 5, NULL, 14.50),
22+
(115 , 5, NULL, 15.65),
23+
(116 , 6, 1, NULL),
24+
(117 , 6, 1, 10),
25+
(118 , 6, 1, 1.1),
26+
(119 , 6, 1, NULL),
27+
(120 , 6, 1, NULL),
28+
(121 , 6, 1, NULL),
29+
(122 , 6, 1, 2.2),
30+
(123 , 6, 1, 20.1),
31+
(124 , 6, 1, -10.4),
32+
(125 , 6, 1, NULL),
33+
(126 , 6, 1, NULL),
34+
(127 , 6, 1, NULL);
35+
select pk, a, b, min(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as min,
36+
max(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as max
37+
from t1;
38+
pk a b min max
39+
101 0 10 10 10
40+
102 0 10 10 10
41+
103 1 10 10 10
42+
104 1 10 10 10
43+
105 2 20 20 20
44+
106 2 20 20 20
45+
107 2 20 10 20
46+
108 2 10 10 20
47+
109 4 20 20 20
48+
110 4 20 20 20
49+
111 5 NULL 1 1
50+
112 5 1 1 1
51+
113 5 NULL 1 1
52+
114 5 NULL NULL NULL
53+
115 5 NULL NULL NULL
54+
116 6 1 1 1
55+
117 6 1 1 1
56+
118 6 1 1 1
57+
119 6 1 1 1
58+
120 6 1 1 1
59+
121 6 1 1 1
60+
122 6 1 1 1
61+
123 6 1 1 1
62+
124 6 1 1 1
63+
125 6 1 1 1
64+
126 6 1 1 1
65+
127 6 1 1 1
66+
select pk, a, c, min(c) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as min,
67+
max(c) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as max
68+
from t1;
69+
pk a c min max
70+
101 0 1.1 1.1 2.1
71+
102 0 2.1 1.1 2.1
72+
103 1 3.1 3.1 4.1
73+
104 1 4.1 3.1 4.1
74+
105 2 6.1 6.1 7.1
75+
106 2 7.1 6.1 8.15
76+
107 2 8.15 5.1 8.15
77+
108 2 5.1 5.1 8.15
78+
109 4 9.15 9.15 10.15
79+
110 4 10.15 9.15 10.15
80+
111 5 11.15 11.15 12.25
81+
112 5 12.25 11.15 13.35
82+
113 5 13.35 12.25 14.5
83+
114 5 14.5 13.35 15.65
84+
115 5 15.65 14.5 15.65
85+
116 6 NULL 10 10
86+
117 6 10 1.1 10
87+
118 6 1.1 1.1 10
88+
119 6 NULL 1.1 1.1
89+
120 6 NULL NULL NULL
90+
121 6 NULL 2.2 2.2
91+
122 6 2.2 2.2 20.1
92+
123 6 20.1 -10.4 20.1
93+
124 6 -10.4 -10.4 20.1
94+
125 6 NULL -10.4 -10.4
95+
126 6 NULL NULL NULL
96+
127 6 NULL NULL NULL
97+
drop table t1;

mysql-test/t/win_min_max.test

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
create table t1 (
2+
pk int primary key,
3+
a int,
4+
b int,
5+
c real
6+
);
7+
8+
9+
insert into t1 values
10+
(101 , 0, 10, 1.1),
11+
(102 , 0, 10, 2.1),
12+
(103 , 1, 10, 3.1),
13+
(104 , 1, 10, 4.1),
14+
(108 , 2, 10, 5.1),
15+
(105 , 2, 20, 6.1),
16+
(106 , 2, 20, 7.1),
17+
(107 , 2, 20, 8.15),
18+
(109 , 4, 20, 9.15),
19+
(110 , 4, 20, 10.15),
20+
(111 , 5, NULL, 11.15),
21+
(112 , 5, 1, 12.25),
22+
(113 , 5, NULL, 13.35),
23+
(114 , 5, NULL, 14.50),
24+
(115 , 5, NULL, 15.65),
25+
(116 , 6, 1, NULL),
26+
(117 , 6, 1, 10),
27+
(118 , 6, 1, 1.1),
28+
(119 , 6, 1, NULL),
29+
(120 , 6, 1, NULL),
30+
(121 , 6, 1, NULL),
31+
(122 , 6, 1, 2.2),
32+
(123 , 6, 1, 20.1),
33+
(124 , 6, 1, -10.4),
34+
(125 , 6, 1, NULL),
35+
(126 , 6, 1, NULL),
36+
(127 , 6, 1, NULL);
37+
38+
39+
--sorted_result
40+
select pk, a, b, min(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as min,
41+
max(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as max
42+
from t1;
43+
44+
--sorted_result
45+
select pk, a, c, min(c) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as min,
46+
max(c) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as max
47+
from t1;
48+
49+
drop table t1;

0 commit comments

Comments
 (0)