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 AND1 FOLLOWING) as min, max(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND1 FOLLOWING) as max
from t1;
pk a b minmax 1010101010 1020101010 1031101010 1041101010 1052202020 1062202020 1072201020 1082101020 1094202020 1104202020 1115 NULL 11 1125111 1135 NULL 11 1145 NULL NULL NULL 1155 NULL NULL NULL 1166111 1176111 1186111 1196111 1206111 1216111 1226111 1236111 1246111 1256111 1266111 1276111
select pk, a, c, min(c) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND1 FOLLOWING) as min, max(c) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND1 FOLLOWING) as max
from t1;
pk a c minmax 10101.11.12.1 10202.11.12.1 10313.13.14.1 10414.13.14.1 10526.16.17.1 10627.16.18.15 10728.155.18.15 10825.15.18.15 10949.159.1510.15 110410.159.1510.15 111511.1511.1512.25 112512.2511.1513.35 113513.3512.2514.5 114514.513.3515.65 115515.6514.515.65 1166 NULL 1010 1176101.110 11861.11.110 1196 NULL 1.11.1 1206 NULL NULL NULL 1216 NULL 2.22.2 12262.22.220.1 123620.1 -10.420.1 1246 -10.4 -10.420.1 1256 NULL -10.4 -10.4 1266 NULL NULL NULL 1276 NULL NULL NULL
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, 20, 'four'),
( 5, 1, 10, 'five'),
( 6, 1, 40, 'six'),
( 7, 1, 30, 'seven'),
( 8, 4,300, 'eight'),
( 9, 4,100, 'nine'),
(10, 4,200, 'ten'),
(11, 4,200, 'eleven');
# First try some invalid argument queries.
select pk, a, b, c, min(c) over (order by pk), max(c) over (order by pk), min(c) over (partition by a order by pk), max(c) over (partition by a order by pk)
from t2;
pk a b c min(c) over (order by pk) max(c) over (order by pk) min(c) over (partition by a order by pk) max(c) over (partition by a order by pk) 101 one one one one one 202 two one two one two 303 three one two one two 4120 four four two four four 5110 five five two five four 6140 six five two five six 7130 seven five two five six 84300 eight eight two eight eight 94100 nine eight two eight nine 104200 ten eight two eight ten 114200 eleven eight two eight ten
# Empty frame
select pk, a, b, c, min(b) over (order by pk rows between 2 following and1 following) as min1, max(b) over (order by pk rows between 2 following and1 following) as max1, min(b) over (partition by a order by pk rows between 2 following and1 following) as min2, max(b) over (partition by a order by pk rows between 2 following and1 following) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one NULL NULL NULL NULL 202 two NULL NULL NULL NULL 303 three NULL NULL NULL NULL 4120 four NULL NULL NULL NULL 5110 five NULL NULL NULL NULL 6140 six NULL NULL NULL NULL 7130 seven NULL NULL NULL NULL 84300 eight NULL NULL NULL NULL 94100 nine NULL NULL NULL NULL 104200 ten NULL NULL NULL NULL 114200 eleven NULL NULL NULL NULL
select pk, a, b, c, min(b) over (order by pk range between 2 following and1 following) as min1, max(b) over (order by pk range between 2 following and1 following) as max1, min(b) over (partition by a order by pk range between 2 following and1 following) as min2, max(b) over (partition by a order by pk range between 2 following and1 following) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one NULL NULL NULL NULL 202 two NULL NULL NULL NULL 303 three NULL NULL NULL NULL 4120 four NULL NULL NULL NULL 5110 five NULL NULL NULL NULL 6140 six NULL NULL NULL NULL 7130 seven NULL NULL NULL NULL 84300 eight NULL NULL NULL NULL 94100 nine NULL NULL NULL NULL 104200 ten NULL NULL NULL NULL 114200 eleven NULL NULL NULL NULL
select pk, a, b, c, min(b) over (order by pk rows between 1 preceding and2 preceding) as min1, max(b) over (order by pk rows between 1 preceding and2 preceding) as max1, min(b) over (partition by a order by pk rows between 1 preceding and2 preceding) as min2, max(b) over (partition by a order by pk rows between 1 preceding and2 preceding) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one NULL NULL NULL NULL 202 two NULL NULL NULL NULL 303 three NULL NULL NULL NULL 4120 four NULL NULL NULL NULL 5110 five NULL NULL NULL NULL 6140 six NULL NULL NULL NULL 7130 seven NULL NULL NULL NULL 84300 eight NULL NULL NULL NULL 94100 nine NULL NULL NULL NULL 104200 ten NULL NULL NULL NULL 114200 eleven NULL NULL NULL NULL
select pk, a, b, c, min(b) over (order by pk range between 1 preceding and2 preceding) as min1, max(b) over (order by pk range between 1 preceding and2 preceding) as max1, min(b) over (partition by a order by pk range between 1 preceding and2 preceding) as min2, max(b) over (partition by a order by pk range between 1 preceding and2 preceding) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one NULL NULL NULL NULL 202 two NULL NULL NULL NULL 303 three NULL NULL NULL NULL 4120 four NULL NULL NULL NULL 5110 five NULL NULL NULL NULL 6140 six NULL NULL NULL NULL 7130 seven NULL NULL NULL NULL 84300 eight NULL NULL NULL NULL 94100 nine NULL NULL NULL NULL 104200 ten NULL NULL NULL NULL 114200 eleven NULL NULL NULL NULL
select pk, a, b, c, min(b) over (order by pk rows between 1 following and0 following) as min1, max(b) over (order by pk rows between 1 following and0 following) as max1, min(b) over (partition by a order by pk rows between 1 following and0 following) as min2, max(b) over (partition by a order by pk rows between 1 following and0 following) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one NULL NULL NULL NULL 202 two NULL NULL NULL NULL 303 three NULL NULL NULL NULL 4120 four NULL NULL NULL NULL 5110 five NULL NULL NULL NULL 6140 six NULL NULL NULL NULL 7130 seven NULL NULL NULL NULL 84300 eight NULL NULL NULL NULL 94100 nine NULL NULL NULL NULL 104200 ten NULL NULL NULL NULL 114200 eleven NULL NULL NULL NULL
select pk, a, b, c, min(b) over (order by pk range between 1 following and0 following) as min1, max(b) over (order by pk range between 1 following and0 following) as max1, min(b) over (partition by a order by pk range between 1 following and0 following) as min2, max(b) over (partition by a order by pk range between 1 following and0 following) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one NULL NULL NULL NULL 202 two NULL NULL NULL NULL 303 three NULL NULL NULL NULL 4120 four NULL NULL NULL NULL 5110 five NULL NULL NULL NULL 6140 six NULL NULL NULL NULL 7130 seven NULL NULL NULL NULL 84300 eight NULL NULL NULL NULL 94100 nine NULL NULL NULL NULL 104200 ten NULL NULL NULL NULL 114200 eleven NULL NULL NULL NULL
select pk, a, b, c, min(b) over (order by pk rows between 1 following and0 preceding) as min1, max(b) over (order by pk rows between 1 following and0 preceding) as max1, min(b) over (partition by a order by pk rows between 1 following and0 preceding) as min2, max(b) over (partition by a order by pk rows between 1 following and0 preceding) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one NULL NULL NULL NULL 202 two NULL NULL NULL NULL 303 three NULL NULL NULL NULL 4120 four NULL NULL NULL NULL 5110 five NULL NULL NULL NULL 6140 six NULL NULL NULL NULL 7130 seven NULL NULL NULL NULL 84300 eight NULL NULL NULL NULL 94100 nine NULL NULL NULL NULL 104200 ten NULL NULL NULL NULL 114200 eleven NULL NULL NULL NULL
select pk, a, b, c, min(b) over (order by pk range between 1 following and0 preceding) as min1, max(b) over (order by pk range between 1 following and0 preceding) as max1, min(b) over (partition by a order by pk range between 1 following and0 preceding) as min2, max(b) over (partition by a order by pk range between 1 following and0 preceding) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one NULL NULL NULL NULL 202 two NULL NULL NULL NULL 303 three NULL NULL NULL NULL 4120 four NULL NULL NULL NULL 5110 five NULL NULL NULL NULL 6140 six NULL NULL NULL NULL 7130 seven NULL NULL NULL NULL 84300 eight NULL NULL NULL NULL 94100 nine NULL NULL NULL NULL 104200 ten NULL NULL NULL NULL 114200 eleven NULL NULL NULL NULL
select pk, a, b, c, min(b) over (order by pk rows between 0 following and1 preceding) as min1, max(b) over (order by pk rows between 0 following and1 preceding) as max1, min(b) over (partition by a order by pk rows between 0 following and1 preceding) as min2, max(b) over (partition by a order by pk rows between 0 following and1 preceding) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one NULL NULL NULL NULL 202 two NULL NULL NULL NULL 303 three NULL NULL NULL NULL 4120 four NULL NULL NULL NULL 5110 five NULL NULL NULL NULL 6140 six NULL NULL NULL NULL 7130 seven NULL NULL NULL NULL 84300 eight NULL NULL NULL NULL 94100 nine NULL NULL NULL NULL 104200 ten NULL NULL NULL NULL 114200 eleven NULL NULL NULL NULL
select pk, a, b, c, min(b) over (order by pk range between 0 following and1 preceding) as min1, max(b) over (order by pk range between 0 following and1 preceding) as max1, min(b) over (partition by a order by pk range between 0 following and1 preceding) as min2, max(b) over (partition by a order by pk range between 0 following and1 preceding) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one NULL NULL NULL NULL 202 two NULL NULL NULL NULL 303 three NULL NULL NULL NULL 4120 four NULL NULL NULL NULL 5110 five NULL NULL NULL NULL 6140 six NULL NULL NULL NULL 7130 seven NULL NULL NULL NULL 84300 eight NULL NULL NULL NULL 94100 nine NULL NULL NULL NULL 104200 ten NULL NULL NULL NULL 114200 eleven NULL NULL NULL NULL
# 1 row frame.
select pk, a, b, c, min(b) over (order by pk rows between current row and current row) as min1, max(b) over (order by pk rows between current row and current row) as max1, min(b) over (partition by a order by pk rows between current row and current row) as min2, max(b) over (partition by a order by pk rows between current row and current row) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 1111 202 two 2222 303 three 3333 4120 four 20202020 5110 five 10101010 6140 six 40404040 7130 seven 30303030 84300 eight 300300300300 94100 nine 100100100100 104200 ten 200200200200 114200 eleven 200200200200
select pk, a, b, c, min(b) over (order by pk rows between 0 preceding and current row) as min1, max(b) over (order by pk rows between 0 preceding and current row) as max1, min(b) over (partition by a order by pk rows between 0 preceding and current row) as min2, max(b) over (partition by a order by pk rows between 0 preceding and current row) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 1111 202 two 2222 303 three 3333 4120 four 20202020 5110 five 10101010 6140 six 40404040 7130 seven 30303030 84300 eight 300300300300 94100 nine 100100100100 104200 ten 200200200200 114200 eleven 200200200200
select pk, a, b, c, min(b) over (order by pk rows between 0 preceding and0 preceding) as min1, max(b) over (order by pk rows between 0 preceding and0 preceding) as max1, min(b) over (partition by a order by pk rows between 0 preceding and0 preceding) as min2, max(b) over (partition by a order by pk rows between 0 preceding and0 preceding) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 1111 202 two 2222 303 three 3333 4120 four 20202020 5110 five 10101010 6140 six 40404040 7130 seven 30303030 84300 eight 300300300300 94100 nine 100100100100 104200 ten 200200200200 114200 eleven 200200200200
select pk, a, b, c, min(b) over (order by pk rows between 1 preceding and1 preceding) as min1, max(b) over (order by pk rows between 1 preceding and1 preceding) as max1, min(b) over (partition by a order by pk rows between 1 preceding and1 preceding) as min2, max(b) over (partition by a order by pk rows between 1 preceding and1 preceding) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one NULL NULL NULL NULL 202 two 1111 303 three 2222 4120 four 33 NULL NULL 5110 five 20202020 6140 six 10101010 7130 seven 40404040 84300 eight 3030 NULL NULL 94100 nine 300300300300 104200 ten 100100100100 114200 eleven 200200200200
select pk, a, b, c, min(b) over (order by pk rows between 1 following and1 following) as min1, max(b) over (order by pk rows between 1 following and1 following) as max1, min(b) over (partition by a order by pk rows between 1 following and1 following) as min2, max(b) over (partition by a order by pk rows between 1 following and1 following) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 2222 202 two 3333 303 three 2020 NULL NULL 4120 four 10101010 5110 five 40404040 6140 six 30303030 7130 seven 300300 NULL NULL 84300 eight 100100100100 94100 nine 200200200200 104200 ten 200200200200 114200 eleven NULL NULL NULL NULL
# Try a larger offset.
select pk, a, b, c, min(b) over (order by pk rows between 3 following and3 following) as min1, max(b) over (order by pk rows between 3 following and3 following) as max1, min(b) over (partition by a order by pk rows between 3 following and3 following) as min2, max(b) over (partition by a order by pk rows between 3 following and3 following) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 2020 NULL NULL 202 two 1010 NULL NULL 303 three 4040 NULL NULL 4120 four 30303030 5110 five 300300 NULL NULL 6140 six 100100 NULL NULL 7130 seven 200200 NULL NULL 84300 eight 200200200200 94100 nine NULL NULL NULL NULL 104200 ten NULL NULL NULL NULL 114200 eleven NULL NULL NULL NULL
select pk, a, b, c, min(b) over (order by pk rows between 3 preceding and3 preceding) as min1, max(b) over (order by pk rows between 3 preceding and3 preceding) as max1, min(b) over (partition by a order by pk rows between 3 preceding and3 preceding) as min2, max(b) over (partition by a order by pk rows between 3 preceding and3 preceding) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one NULL NULL NULL NULL 202 two NULL NULL NULL NULL 303 three NULL NULL NULL NULL 4120 four 11 NULL NULL 5110 five 22 NULL NULL 6140 six 33 NULL NULL 7130 seven 20202020 84300 eight 1010 NULL NULL 94100 nine 4040 NULL NULL 104200 ten 3030 NULL NULL 114200 eleven 300300300300
# 2 row frame.
select pk, a, b, c, min(b) over (order by pk rows between current row and1 following) as min1, max(b) over (order by pk rows between current row and1 following) as max1, min(b) over (partition by a order by pk rows between current row and1 following) as min2, max(b) over (partition by a order by pk rows between current row and1 following) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 1212 202 two 2323 303 three 32033 4120 four 10201020 5110 five 10401040 6140 six 30403040 7130 seven 303003030 84300 eight 100300100300 94100 nine 100200100200 104200 ten 200200200200 114200 eleven 200200200200
select pk, a, b, c, min(b) over (order by pk rows between 0 preceding and1 following) as min1, max(b) over (order by pk rows between 0 preceding and1 following) as max1, min(b) over (partition by a order by pk rows between 0 preceding and1 following) as min2, max(b) over (partition by a order by pk rows between 0 preceding and1 following) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 1212 202 two 2323 303 three 32033 4120 four 10201020 5110 five 10401040 6140 six 30403040 7130 seven 303003030 84300 eight 100300100300 94100 nine 100200100200 104200 ten 200200200200 114200 eleven 200200200200
select pk, a, b, c, min(b) over (order by pk rows between 1 preceding and current row) as min1, max(b) over (order by pk rows between 1 preceding and current row) as max1, min(b) over (partition by a order by pk rows between 1 preceding and current row) as min2, max(b) over (partition by a order by pk rows between 1 preceding and current row) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 1111 202 two 1212 303 three 2323 4120 four 3202020 5110 five 10201020 6140 six 10401040 7130 seven 30403040 84300 eight 30300300300 94100 nine 100300100300 104200 ten 100200100200 114200 eleven 200200200200
select pk, a, b, c, min(b) over (order by pk rows between 1 preceding and0 preceding) as min1, max(b) over (order by pk rows between 1 preceding and0 preceding) as max1, min(b) over (partition by a order by pk rows between 1 preceding and0 preceding) as min2, max(b) over (partition by a order by pk rows between 1 preceding and0 preceding) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 1111 202 two 1212 303 three 2323 4120 four 3202020 5110 five 10201020 6140 six 10401040 7130 seven 30403040 84300 eight 30300300300 94100 nine 100300100300 104200 ten 100200100200 114200 eleven 200200200200
# Try a larger frame/offset.
select pk, a, b, c, min(b) over (order by pk rows between current row and3 following) as min1, max(b) over (order by pk rows between current row and3 following) as max1, min(b) over (partition by a order by pk rows between current row and3 following) as min2, max(b) over (partition by a order by pk rows between current row and3 following) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 12013 202 two 22023 303 three 34033 4120 four 10401040 5110 five 103001040 6140 six 303003040 7130 seven 303003030 84300 eight 100300100300 94100 nine 100200100200 104200 ten 200200200200 114200 eleven 200200200200
select pk, a, b, c, min(b) over (order by pk rows between 2 preceding and1 following) as min1, max(b) over (order by pk rows between 2 preceding and1 following) as max1, min(b) over (partition by a order by pk rows between 2 preceding and1 following) as min2, max(b) over (partition by a order by pk rows between 2 preceding and1 following) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 1212 202 two 1313 303 three 12013 4120 four 2201020 5110 five 3401040 6140 six 10401040 7130 seven 103001040 84300 eight 30300100300 94100 nine 30300100300 104200 ten 100300100300 114200 eleven 100200100200
select pk, a, b, c, min(b) over (order by pk rows between 3 preceding and current row) as min1, max(b) over (order by pk rows between 3 preceding and current row) as max1, min(b) over (partition by a order by pk rows between 3 preceding and current row) as min2, max(b) over (partition by a order by pk rows between 3 preceding and current row) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 1111 202 two 1212 303 three 1313 4120 four 1202020 5110 five 2201020 6140 six 3401040 7130 seven 10401040 84300 eight 10300300300 94100 nine 30300100300 104200 ten 30300100300 114200 eleven 100300100300
select pk, a, b, c, min(b) over (order by pk rows between 3 preceding and0 preceding) as min1, max(b) over (order by pk rows between 3 preceding and0 preceding) as max1, min(b) over (partition by a order by pk rows between 3 preceding and0 preceding) as min2, max(b) over (partition by a order by pk rows between 3 preceding and0 preceding) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 1111 202 two 1212 303 three 1313 4120 four 1202020 5110 five 2201020 6140 six 3401040 7130 seven 10401040 84300 eight 10300300300 94100 nine 30300100300 104200 ten 30300100300 114200 eleven 100300100300
# Check range frame bounds
select pk, a, b, c, min(b) over (order by pk range between current row and current row) as min1, max(b) over (order by pk range between current row and current row) as max1, min(b) over (partition by a order by pk range between current row and current row) as min2, max(b) over (partition by a order by pk range between current row and current row) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 1111 202 two 2222 303 three 3333 4120 four 20202020 5110 five 10101010 6140 six 40404040 7130 seven 30303030 84300 eight 300300300300 94100 nine 100100100100 104200 ten 200200200200 114200 eleven 200200200200
select pk, a, b, c, min(b) over (order by pk range between 0 preceding and current row) as min1, max(b) over (order by pk range between 0 preceding and current row) as max1, min(b) over (partition by a order by pk range between 0 preceding and current row) as min2, max(b) over (partition by a order by pk range between 0 preceding and current row) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 1111 202 two 2222 303 three 3333 4120 four 20202020 5110 five 10101010 6140 six 40404040 7130 seven 30303030 84300 eight 300300300300 94100 nine 100100100100 104200 ten 200200200200 114200 eleven 200200200200
select pk, a, b, c, min(b) over (order by pk range between 0 preceding and0 preceding) as min1, max(b) over (order by pk range between 0 preceding and0 preceding) as max1, min(b) over (partition by a order by pk range between 0 preceding and0 preceding) as min2, max(b) over (partition by a order by pk range between 0 preceding and0 preceding) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 1111 202 two 2222 303 three 3333 4120 four 20202020 5110 five 10101010 6140 six 40404040 7130 seven 30303030 84300 eight 300300300300 94100 nine 100100100100 104200 ten 200200200200 114200 eleven 200200200200
select pk, a, b, c, min(b) over (order by pk range between 1 preceding and1 preceding) as min1, max(b) over (order by pk range between 1 preceding and1 preceding) as max1, min(b) over (partition by a order by pk range between 1 preceding and1 preceding) as min2, max(b) over (partition by a order by pk range between 1 preceding and1 preceding) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one NULL NULL NULL NULL 202 two 1111 303 three 2222 4120 four 33 NULL NULL 5110 five 20202020 6140 six 10101010 7130 seven 40404040 84300 eight 3030 NULL NULL 94100 nine 300300300300 104200 ten 100100100100 114200 eleven 200200200200
select pk, a, b, c, min(b) over (order by pk range between 1 following and1 following) as min1, max(b) over (order by pk range between 1 following and1 following) as max1, min(b) over (partition by a order by pk range between 1 following and1 following) as min2, max(b) over (partition by a order by pk range between 1 following and1 following) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 2222 202 two 3333 303 three 2020 NULL NULL 4120 four 10101010 5110 five 40404040 6140 six 30303030 7130 seven 300300 NULL NULL 84300 eight 100100100100 94100 nine 200200200200 104200 ten 200200200200 114200 eleven NULL NULL NULL NULL
# Try a larger offset.
select pk, a, b, c, min(b) over (order by pk range between 3 following and3 following) as min1, max(b) over (order by pk range between 3 following and3 following) as max1, min(b) over (partition by a order by pk range between 3 following and3 following) as min2, max(b) over (partition by a order by pk range between 3 following and3 following) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 2020 NULL NULL 202 two 1010 NULL NULL 303 three 4040 NULL NULL 4120 four 30303030 5110 five 300300 NULL NULL 6140 six 100100 NULL NULL 7130 seven 200200 NULL NULL 84300 eight 200200200200 94100 nine NULL NULL NULL NULL 104200 ten NULL NULL NULL NULL 114200 eleven NULL NULL NULL NULL
select pk, a, b, c, min(b) over (order by pk range between 3 preceding and3 preceding) as min1, max(b) over (order by pk range between 3 preceding and3 preceding) as max1, min(b) over (partition by a order by pk range between 3 preceding and3 preceding) as min2, max(b) over (partition by a order by pk range between 3 preceding and3 preceding) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one NULL NULL NULL NULL 202 two NULL NULL NULL NULL 303 three NULL NULL NULL NULL 4120 four 11 NULL NULL 5110 five 22 NULL NULL 6140 six 33 NULL NULL 7130 seven 20202020 84300 eight 1010 NULL NULL 94100 nine 4040 NULL NULL 104200 ten 3030 NULL NULL 114200 eleven 300300300300
# 2 row frame.
select pk, a, b, c, min(b) over (order by pk range between current row and1 following) as min1, max(b) over (order by pk range between current row and1 following) as max1, min(b) over (partition by a order by pk range between current row and1 following) as min2, max(b) over (partition by a order by pk range between current row and1 following) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 1212 202 two 2323 303 three 32033 4120 four 10201020 5110 five 10401040 6140 six 30403040 7130 seven 303003030 84300 eight 100300100300 94100 nine 100200100200 104200 ten 200200200200 114200 eleven 200200200200
select pk, a, b, c, min(b) over (order by pk range between 0 preceding and1 following) as min1, max(b) over (order by pk range between 0 preceding and1 following) as max1, min(b) over (partition by a order by pk range between 0 preceding and1 following) as min2, max(b) over (partition by a order by pk range between 0 preceding and1 following) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 1212 202 two 2323 303 three 32033 4120 four 10201020 5110 five 10401040 6140 six 30403040 7130 seven 303003030 84300 eight 100300100300 94100 nine 100200100200 104200 ten 200200200200 114200 eleven 200200200200
select pk, a, b, c, min(b) over (order by pk range between 1 preceding and current row) as min1, max(b) over (order by pk range between 1 preceding and current row) as max1, min(b) over (partition by a order by pk range between 1 preceding and current row) as min2, max(b) over (partition by a order by pk range between 1 preceding and current row) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 1111 202 two 1212 303 three 2323 4120 four 3202020 5110 five 10201020 6140 six 10401040 7130 seven 30403040 84300 eight 30300300300 94100 nine 100300100300 104200 ten 100200100200 114200 eleven 200200200200
select pk, a, b, c, min(b) over (order by pk range between 1 preceding and0 preceding) as min1, max(b) over (order by pk range between 1 preceding and0 preceding) as max1, min(b) over (partition by a order by pk range between 1 preceding and0 preceding) as min2, max(b) over (partition by a order by pk range between 1 preceding and0 preceding) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 1111 202 two 1212 303 three 2323 4120 four 3202020 5110 five 10201020 6140 six 10401040 7130 seven 30403040 84300 eight 30300300300 94100 nine 100300100300 104200 ten 100200100200 114200 eleven 200200200200
# Try a larger frame/offset.
select pk, a, b, c, min(b) over (order by pk range between current row and3 following) as min1, max(b) over (order by pk range between current row and3 following) as max1, min(b) over (partition by a order by pk range between current row and3 following) as min2, max(b) over (partition by a order by pk range between current row and3 following) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 12013 202 two 22023 303 three 34033 4120 four 10401040 5110 five 103001040 6140 six 303003040 7130 seven 303003030 84300 eight 100300100300 94100 nine 100200100200 104200 ten 200200200200 114200 eleven 200200200200
select pk, a, b, c, min(b) over (order by pk range between 2 preceding and1 following) as min1, max(b) over (order by pk range between 2 preceding and1 following) as max1, min(b) over (partition by a order by pk range between 2 preceding and1 following) as min2, max(b) over (partition by a order by pk range between 2 preceding and1 following) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 1212 202 two 1313 303 three 12013 4120 four 2201020 5110 five 3401040 6140 six 10401040 7130 seven 103001040 84300 eight 30300100300 94100 nine 30300100300 104200 ten 100300100300 114200 eleven 100200100200
select pk, a, b, c, min(b) over (order by pk range between 3 preceding and current row) as min1, max(b) over (order by pk range between 3 preceding and current row) as max1, min(b) over (partition by a order by pk range between 3 preceding and current row) as min2, max(b) over (partition by a order by pk range between 3 preceding and current row) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 1111 202 two 1212 303 three 1313 4120 four 1202020 5110 five 2201020 6140 six 3401040 7130 seven 10401040 84300 eight 10300300300 94100 nine 30300100300 104200 ten 30300100300 114200 eleven 100300100300
select pk, a, b, c, min(b) over (order by pk range between 3 preceding and0 preceding) as min1, max(b) over (order by pk range between 3 preceding and0 preceding) as max1, min(b) over (partition by a order by pk range between 3 preceding and0 preceding) as min2, max(b) over (partition by a order by pk range between 3 preceding and0 preceding) as max2
from t2;
pk a b c min1 max1 min2 max2 101 one 1111 202 two 1212 303 three 1313 4120 four 1202020 5110 five 2201020 6140 six 3401040 7130 seven 10401040 84300 eight 10300300300 94100 nine 30300100300 104200 ten 30300100300 114200 eleven 100300100300
drop table t2;
drop table t1;
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet am 2026-10-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.