-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add min/max test cases for window functions
- Loading branch information
Showing
2 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
create table t1 ( | ||
pk int primary key, | ||
a int, | ||
b int, | ||
c real | ||
); | ||
insert into t1 values | ||
(101 , 0, 10, 1.1), | ||
(102 , 0, 10, 2.1), | ||
(103 , 1, 10, 3.1), | ||
(104 , 1, 10, 4.1), | ||
(108 , 2, 10, 5.1), | ||
(105 , 2, 20, 6.1), | ||
(106 , 2, 20, 7.1), | ||
(107 , 2, 20, 8.15), | ||
(109 , 4, 20, 9.15), | ||
(110 , 4, 20, 10.15), | ||
(111 , 5, NULL, 11.15), | ||
(112 , 5, 1, 12.25), | ||
(113 , 5, NULL, 13.35), | ||
(114 , 5, NULL, 14.50), | ||
(115 , 5, NULL, 15.65), | ||
(116 , 6, 1, NULL), | ||
(117 , 6, 1, 10), | ||
(118 , 6, 1, 1.1), | ||
(119 , 6, 1, NULL), | ||
(120 , 6, 1, NULL), | ||
(121 , 6, 1, NULL), | ||
(122 , 6, 1, 2.2), | ||
(123 , 6, 1, 20.1), | ||
(124 , 6, 1, -10.4), | ||
(125 , 6, 1, NULL), | ||
(126 , 6, 1, NULL), | ||
(127 , 6, 1, NULL); | ||
select pk, a, b, min(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as min, | ||
max(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as max | ||
from t1; | ||
pk a b min max | ||
101 0 10 10 10 | ||
102 0 10 10 10 | ||
103 1 10 10 10 | ||
104 1 10 10 10 | ||
105 2 20 20 20 | ||
106 2 20 20 20 | ||
107 2 20 10 20 | ||
108 2 10 10 20 | ||
109 4 20 20 20 | ||
110 4 20 20 20 | ||
111 5 NULL 1 1 | ||
112 5 1 1 1 | ||
113 5 NULL 1 1 | ||
114 5 NULL NULL NULL | ||
115 5 NULL NULL NULL | ||
116 6 1 1 1 | ||
117 6 1 1 1 | ||
118 6 1 1 1 | ||
119 6 1 1 1 | ||
120 6 1 1 1 | ||
121 6 1 1 1 | ||
122 6 1 1 1 | ||
123 6 1 1 1 | ||
124 6 1 1 1 | ||
125 6 1 1 1 | ||
126 6 1 1 1 | ||
127 6 1 1 1 | ||
select pk, a, c, min(c) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as min, | ||
max(c) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as max | ||
from t1; | ||
pk a c min max | ||
101 0 1.1 1.1 2.1 | ||
102 0 2.1 1.1 2.1 | ||
103 1 3.1 3.1 4.1 | ||
104 1 4.1 3.1 4.1 | ||
105 2 6.1 6.1 7.1 | ||
106 2 7.1 6.1 8.15 | ||
107 2 8.15 5.1 8.15 | ||
108 2 5.1 5.1 8.15 | ||
109 4 9.15 9.15 10.15 | ||
110 4 10.15 9.15 10.15 | ||
111 5 11.15 11.15 12.25 | ||
112 5 12.25 11.15 13.35 | ||
113 5 13.35 12.25 14.5 | ||
114 5 14.5 13.35 15.65 | ||
115 5 15.65 14.5 15.65 | ||
116 6 NULL 10 10 | ||
117 6 10 1.1 10 | ||
118 6 1.1 1.1 10 | ||
119 6 NULL 1.1 1.1 | ||
120 6 NULL NULL NULL | ||
121 6 NULL 2.2 2.2 | ||
122 6 2.2 2.2 20.1 | ||
123 6 20.1 -10.4 20.1 | ||
124 6 -10.4 -10.4 20.1 | ||
125 6 NULL -10.4 -10.4 | ||
126 6 NULL NULL NULL | ||
127 6 NULL NULL NULL | ||
drop table t1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
create table t1 ( | ||
pk int primary key, | ||
a int, | ||
b int, | ||
c real | ||
); | ||
|
||
|
||
insert into t1 values | ||
(101 , 0, 10, 1.1), | ||
(102 , 0, 10, 2.1), | ||
(103 , 1, 10, 3.1), | ||
(104 , 1, 10, 4.1), | ||
(108 , 2, 10, 5.1), | ||
(105 , 2, 20, 6.1), | ||
(106 , 2, 20, 7.1), | ||
(107 , 2, 20, 8.15), | ||
(109 , 4, 20, 9.15), | ||
(110 , 4, 20, 10.15), | ||
(111 , 5, NULL, 11.15), | ||
(112 , 5, 1, 12.25), | ||
(113 , 5, NULL, 13.35), | ||
(114 , 5, NULL, 14.50), | ||
(115 , 5, NULL, 15.65), | ||
(116 , 6, 1, NULL), | ||
(117 , 6, 1, 10), | ||
(118 , 6, 1, 1.1), | ||
(119 , 6, 1, NULL), | ||
(120 , 6, 1, NULL), | ||
(121 , 6, 1, NULL), | ||
(122 , 6, 1, 2.2), | ||
(123 , 6, 1, 20.1), | ||
(124 , 6, 1, -10.4), | ||
(125 , 6, 1, NULL), | ||
(126 , 6, 1, NULL), | ||
(127 , 6, 1, NULL); | ||
|
||
|
||
--sorted_result | ||
select pk, a, b, min(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as min, | ||
max(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as max | ||
from t1; | ||
|
||
--sorted_result | ||
select pk, a, c, min(c) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as min, | ||
max(c) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as max | ||
from t1; | ||
|
||
drop table t1; |