--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT depname, empno, salary, sum(salary) OVER w FROM empsalary WINDOW w AS (PARTITION BY depname) ORDER BY depname, salary;

   depname    | empno | salary | column3 
--------------+-------+--------+---------
   b'develop' |     7 |   4200 |   25100 
   b'develop' |     9 |   4500 |   25100 
   b'develop' |    10 |   5200 |   25100 
   b'develop' |    11 |   5200 |   25100 
   b'develop' |     8 |   6000 |   25100 
 b'personnel' |     5 |   3500 |    7400 
 b'personnel' |     2 |   3900 |    7400 
     b'sales' |     3 |   4800 |   14600 
     b'sales' |     4 |   4800 |   14600 
     b'sales' |     1 |   5000 |   14600 
(10 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT depname, empno, salary, rank() OVER w FROM empsalary WINDOW w AS (PARTITION BY depname ORDER BY salary) ORDER BY salary, depname;

   depname    | empno | salary | column3 
--------------+-------+--------+---------
 b'personnel' |     5 |   3500 |       1 
 b'personnel' |     2 |   3900 |       2 
   b'develop' |     7 |   4200 |       1 
   b'develop' |     9 |   4500 |       2 
     b'sales' |     4 |   4800 |       1 
     b'sales' |     3 |   4800 |       1 
     b'sales' |     1 |   5000 |       3 
   b'develop' |    10 |   5200 |       3 
   b'develop' |    11 |   5200 |       3 
   b'develop' |     8 |   6000 |       5 
(10 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT four, ten, SUM(SUM(four)) OVER w, AVG(ten) FROM tenk1
GROUP BY four, ten WINDOW w AS (PARTITION BY four) ORDER BY four, ten;

 four | ten | column2 | column3 
------+-----+---------+---------
    0 |   0 |       0 |     0.0 
    0 |   2 |       0 |     2.0 
    0 |   4 |       0 |     4.0 
    0 |   6 |       0 |     6.0 
    0 |   8 |       0 |     8.0 
    1 |   1 |    2500 |     1.0 
    1 |   3 |    2500 |     3.0 
    1 |   5 |    2500 |     5.0 
    1 |   7 |    2500 |     7.0 
    1 |   9 |    2500 |     9.0 
    2 |   0 |    5000 |     0.0 
    2 |   2 |    5000 |     2.0 
    2 |   4 |    5000 |     4.0 
    2 |   6 |    5000 |     6.0 
    2 |   8 |    5000 |     8.0 
    3 |   1 |    7500 |     1.0 
    3 |   3 |    7500 |     3.0 
    3 |   5 |    7500 |     5.0 
    3 |   7 |    7500 |     7.0 
    3 |   9 |    7500 |     9.0 
(20 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT depname, empno, salary, sum(salary) OVER w FROM empsalary WINDOW w AS (PARTITION BY depname) ORDER BY depname, salary, empno;

   depname    | empno | salary | column3 
--------------+-------+--------+---------
   b'develop' |     7 |   4200 |   25100 
   b'develop' |     9 |   4500 |   25100 
   b'develop' |    10 |   5200 |   25100 
   b'develop' |    11 |   5200 |   25100 
   b'develop' |     8 |   6000 |   25100 
 b'personnel' |     5 |   3500 |    7400 
 b'personnel' |     2 |   3900 |    7400 
     b'sales' |     3 |   4800 |   14600 
     b'sales' |     4 |   4800 |   14600 
     b'sales' |     1 |   5000 |   14600 
(10 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT depname, empno, salary, rank() OVER w AS r FROM empsalary WINDOW w AS (PARTITION BY depname ORDER BY salary) ORDER BY r;

   depname    | empno | salary | r 
--------------+-------+--------+---
   b'develop' |     7 |   4200 | 1 
     b'sales' |     4 |   4800 | 1 
     b'sales' |     3 |   4800 | 1 
 b'personnel' |     5 |   3500 | 1 
 b'personnel' |     2 |   3900 | 2 
   b'develop' |     9 |   4500 | 2 
   b'develop' |    11 |   5200 | 3 
   b'develop' |    10 |   5200 | 3 
     b'sales' |     1 |   5000 | 3 
   b'develop' |     8 |   6000 | 5 
(10 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT COUNT(*) OVER w AS cnt FROM tenk1 WHERE unique2 < 10 WINDOW w AS () ORDER BY cnt;

 cnt 
-----
  10 
  10 
  10 
  10 
  10 
  10 
  10 
  10 
  10 
  10 
(10 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT four FROM tenk1 WHERE FALSE WINDOW w AS (PARTITION BY ten) ORDER BY four;

(0 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT sum(four) OVER w AS sum_1, ten, four FROM tenk1 WHERE unique2 < 10 WINDOW w AS (PARTITION BY ten ORDER BY unique2) ORDER BY sum_1, ten, four;

 sum_1 | ten | four 
-------+-----+------
     0 |   0 |    0 
     0 |   0 |    0 
     0 |   4 |    0 
     1 |   7 |    1 
     1 |   9 |    1 
     2 |   0 |    2 
     3 |   1 |    3 
     3 |   3 |    3 
     4 |   1 |    1 
     5 |   1 |    1 
(10 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT row_number() OVER w AS rnum_1 FROM tenk1 WHERE unique2 < 10 WINDOW w AS (ORDER BY unique2) ORDER BY rnum_1;

 rnum_1 
--------
      1 
      2 
      3 
      4 
      5 
      6 
      7 
      8 
      9 
     10 
(10 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT rank() OVER w AS rank_1, ten, four FROM tenk1 WHERE unique2 < 10 WINDOW w AS (PARTITION BY four ORDER BY ten) ORDER BY rank_1, ten, four;

 rank_1 | ten | four 
--------+-----+------
      1 |   0 |    0 
      1 |   0 |    0 
      1 |   0 |    2 
      1 |   1 |    1 
      1 |   1 |    1 
      1 |   1 |    3 
      2 |   3 |    3 
      3 |   4 |    0 
      3 |   7 |    1 
      4 |   9 |    1 
(10 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT dense_rank() OVER w, ten, four FROM tenk1 WHERE unique2 < 10 WINDOW w AS (PARTITION BY four ORDER BY ten) ORDER BY ten, four;

 column0 | ten | four 
---------+-----+------
       1 |   0 |    0 
       1 |   0 |    0 
       1 |   0 |    2 
       1 |   1 |    1 
       1 |   1 |    1 
       1 |   1 |    3 
       2 |   3 |    3 
       2 |   4 |    0 
       2 |   7 |    1 
       3 |   9 |    1 
(10 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT lag(ten) OVER w, ten, four FROM tenk1 WHERE unique2 < 10 WINDOW w AS (PARTITION BY four ORDER BY ten) ORDER BY ten, four;

 column0 | ten | four 
---------+-----+------
    None |   0 |    0 
       0 |   0 |    0 
    None |   0 |    2 
    None |   1 |    1 
       1 |   1 |    1 
    None |   1 |    3 
       1 |   3 |    3 
       0 |   4 |    0 
       1 |   7 |    1 
       7 |   9 |    1 
(10 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT lead(ten) OVER w, ten, four FROM tenk1 WHERE unique2 < 10 WINDOW w AS (PARTITION BY four ORDER BY ten) ORDER BY ten, four;

 column0 | ten | four 
---------+-----+------
       0 |   0 |    0 
       4 |   0 |    0 
    None |   0 |    2 
       1 |   1 |    1 
       7 |   1 |    1 
       3 |   1 |    3 
    None |   3 |    3 
    None |   4 |    0 
       9 |   7 |    1 
    None |   9 |    1 
(10 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT lead(ten * 2, 1) OVER w, ten, four FROM tenk1 WHERE unique2 < 10 WINDOW w AS (PARTITION BY four ORDER BY ten) ORDER BY ten, four;

 column0 | ten | four 
---------+-----+------
       0 |   0 |    0 
       8 |   0 |    0 
    None |   0 |    2 
       2 |   1 |    1 
      14 |   1 |    1 
       6 |   1 |    3 
    None |   3 |    3 
    None |   4 |    0 
      18 |   7 |    1 
    None |   9 |    1 
(10 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT first_value(ten) OVER w, ten, four FROM tenk1 WHERE unique2 < 10 WINDOW w AS (PARTITION BY four ORDER BY ten) ORDER BY ten, four;

 column0 | ten | four 
---------+-----+------
       0 |   0 |    0 
       0 |   0 |    0 
       0 |   0 |    2 
       1 |   1 |    1 
       1 |   1 |    1 
       1 |   1 |    3 
       1 |   3 |    3 
       0 |   4 |    0 
       1 |   7 |    1 
       1 |   9 |    1 
(10 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT last_value(four) OVER w, last_value(four) OVER w, ten, four FROM tenk1 WHERE unique2 < 10 WINDOW w AS (ORDER BY ten) ORDER BY ten, four;

 column0 | column1 | ten | four 
---------+---------+-----+------
       0 |       0 |   0 |    0 
       0 |       0 |   0 |    0 
       2 |       2 |   0 |    2 
       1 |       1 |   1 |    1 
       1 |       1 |   1 |    1 
       3 |       3 |   1 |    3 
       3 |       3 |   3 |    3 
       0 |       0 |   4 |    0 
       1 |       1 |   7 |    1 
       1 |       1 |   9 |    1 
(10 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT last_value(ten) OVER w, ten, four FROM
    (SELECT * FROM tenk1 WHERE unique2 < 10 ORDER BY four, ten LIMIT 1000)
WINDOW w AS (PARTITION BY four ORDER BY ten)
ORDER BY four, ten;

 column0 | ten | four 
---------+-----+------
       0 |   0 |    0 
       0 |   0 |    0 
       4 |   4 |    0 
       1 |   1 |    1 
       1 |   1 |    1 
       7 |   7 |    1 
       9 |   9 |    1 
       0 |   0 |    2 
       1 |   1 |    3 
       3 |   3 |    3 
(10 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT ten, two, sum(hundred) AS gsum, sum(sum(hundred)) OVER w AS wsum
FROM tenk1 GROUP BY ten, two WINDOW w AS (PARTITION BY two ORDER BY ten)
ORDER BY ten, two;

 ten | two | gsum  |  wsum  
-----+-----+-------+--------
   0 |   0 | 45000 |  45000 
   1 |   1 | 46000 |  46000 
   2 |   0 | 47000 |  92000 
   3 |   1 | 48000 |  94000 
   4 |   0 | 49000 | 141000 
   5 |   1 | 50000 | 144000 
   6 |   0 | 51000 | 192000 
   7 |   1 | 52000 | 196000 
   8 |   0 | 53000 | 245000 
   9 |   1 | 54000 | 250000 
(10 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT count(*) OVER w, four FROM (SELECT * FROM tenk1 WHERE two = 1) WHERE unique2 < 10 WINDOW w AS (PARTITION BY four) ORDER BY four;

 column0 | four 
---------+------
       4 |    1 
       4 |    1 
       4 |    1 
       4 |    1 
       2 |    3 
       2 |    3 
(6 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT (count(*) OVER w + sum(hundred) OVER w) AS cntsum
FROM tenk1 WHERE unique2 < 10
WINDOW w AS (PARTITION BY four ORDER BY ten)
ORDER BY cntsum;

 cntsum 
--------
     21 
     22 
     22 
     24 
     51 
     82 
     87 
     92 
     92 
    136 
(10 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT * FROM(
  SELECT count(*) OVER w1 +
    sum(hundred) OVER w2 AS total,
    count(*) OVER w1 AS fourcount,
    sum(hundred) OVER w2 AS twosum
    FROM tenk1
    WINDOW w1 AS (PARTITION BY four ORDER BY ten), w2 AS (PARTITION BY two ORDER BY ten)
)
WHERE total <> fourcount + twosum
ORDER BY total, fourcount, twosum;

(0 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT avg(four) OVER w AS avg_1 FROM tenk1 WHERE unique2 < 10 WINDOW w AS (PARTITION BY four ORDER BY thousand / 100) ORDER BY avg_1;

 avg_1 
-------
   0.0 
   0.0 
   0.0 
   1.0 
   1.0 
   1.0 
   1.0 
   2.0 
   3.0 
   3.0 
(10 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT ten, two, sum(hundred) AS gsum, sum(sum(hundred)) OVER win AS wsum
FROM tenk1 GROUP BY ten, two WINDOW win AS (PARTITION BY two ORDER BY ten)
ORDER BY wsum, ten, two;

 ten | two | gsum  |  wsum  
-----+-----+-------+--------
   0 |   0 | 45000 |  45000 
   1 |   1 | 46000 |  46000 
   2 |   0 | 47000 |  92000 
   3 |   1 | 48000 |  94000 
   4 |   0 | 49000 | 141000 
   5 |   1 | 50000 | 144000 
   6 |   0 | 51000 | 192000 
   7 |   1 | 52000 | 196000 
   8 |   0 | 53000 | 245000 
   9 |   1 | 54000 | 250000 
(10 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT sum(salary) AS sum_salary,
    row_number() OVER w1 AS rnum_1,
    sum(sum(salary)) OVER w2 AS sum_sum_salary
FROM empsalary GROUP BY depname
WINDOW w1 AS (ORDER BY depname), w2 AS (ORDER BY depname DESC)
ORDER BY sum_salary, rnum_1, sum_sum_salary;

 sum_salary | rnum_1 | sum_sum_salary 
------------+--------+----------------
       7400 |      2 |          22000 
      14600 |      3 |          14600 
      25100 |      1 |          47100 
(3 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT sum(salary) OVER w1 AS sum_salary, count(*) OVER w2 AS cnt
FROM empsalary WINDOW w1 AS (ORDER BY salary), w2 AS (ORDER BY salary)
ORDER BY sum_salary, cnt;

 sum_salary | cnt 
------------+-----
       3500 |   1 
       7400 |   2 
      11600 |   3 
      16100 |   4 
      20900 |   5 
      25700 |   6 
      30700 |   7 
      35900 |   8 
      41100 |   9 
      47100 |  10 
(10 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT count(*) OVER w AS cnt FROM (SELECT * FROM tenk1 WHERE FALSE) WINDOW w AS (PARTITION BY four) ORDER BY cnt;

(0 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT sum(salary) OVER w AS sum_salary, rank() OVER w as rank_1 FROM empsalary WINDOW w AS (PARTITION BY depname ORDER BY salary DESC)
ORDER BY sum_salary, rank_1;

 sum_salary | rank_1 
------------+--------
       3900 |      1 
       5000 |      1 
       6000 |      1 
       7400 |      2 
       9800 |      2 
      11200 |      2 
      14600 |      2 
      16400 |      2 
      20900 |      4 
      25100 |      5 
(10 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT empno, depname, salary, bonus, depadj, MIN(bonus) OVER w, MAX(depadj) OVER w FROM(
    SELECT empsalary.*,
        CASE WHEN enroll_date < DateTime::MakeDatetime(DateTime::Parse("%Y-%m-%d")('2007-08-01'))
            THEN 2008 - DateTime::GetYear(enroll_date)
            ELSE 42 END * 500 AS bonus,
        CASE WHEN AVG(salary) OVER wi < salary
            THEN 200
            ELSE 42 END AS depadj
    FROM empsalary
    WINDOW wi AS (PARTITION BY depname)
)
WINDOW w AS (ORDER BY empno)
ORDER BY empno;

 empno |   depname    | salary | bonus | depadj | column5 | column6 
-------+--------------+--------+-------+--------+---------+---------
     1 |     b'sales' |   5000 |  1000 |    200 |    1000 |     200 
     2 | b'personnel' |   3900 |  1000 |    200 |    1000 |     200 
     3 |     b'sales' |   4800 | 21000 |     42 |    1000 |     200 
     4 |     b'sales' |   4800 | 21000 |     42 |    1000 |     200 
     5 | b'personnel' |   3500 | 21000 |     42 |    1000 |     200 
     7 |   b'develop' |   4200 | 21000 |     42 |    1000 |     200 
     8 |   b'develop' |   6000 |  1000 |    200 |    1000 |     200 
     9 |   b'develop' |   4500 | 21000 |     42 |    1000 |     200 
    10 |   b'develop' |   5200 | 21000 |    200 |    1000 |     200 
    11 |   b'develop' |   5200 | 21000 |    200 |    1000 |     200 
(10 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT SUM(COUNT(f1)) OVER w AS sum_cnt FROM int4_tbl WHERE f1=42 WINDOW w AS () ORDER BY sum_cnt;

 sum_cnt 
---------
       0 
(1 row0)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
select ten,
  sum(unique1) + sum(unique2) as res,
  rank() over w as rank
from tenk1
group by ten
window w AS (order by sum(unique1) + sum(unique2))
order by ten;

 ten |   res    | rank 
-----+----------+------
   0 |  9976146 |    4 
   1 | 10114187 |    9 
   2 | 10059554 |    8 
   3 |  9878541 |    1 
   4 |  9881005 |    2 
   5 |  9981670 |    5 
   6 |  9947099 |    3 
   7 | 10120309 |   10 
   8 |  9991305 |    6 
   9 | 10040184 |    7 
(10 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT four, ten,
	sum(ten) over w,
	last_value(ten) over w
FROM (select distinct ten, four from tenk1)
WINDOW w AS (partition by four order by ten)
ORDER BY four, ten;

 four | ten | column2 | column3 
------+-----+---------+---------
    0 |   0 |       0 |       0 
    0 |   2 |       2 |       2 
    0 |   4 |       6 |       4 
    0 |   6 |      12 |       6 
    0 |   8 |      20 |       8 
    1 |   1 |       1 |       1 
    1 |   3 |       4 |       3 
    1 |   5 |       9 |       5 
    1 |   7 |      16 |       7 
    1 |   9 |      25 |       9 
    2 |   0 |       0 |       0 
    2 |   2 |       2 |       2 
    2 |   4 |       6 |       4 
    2 |   6 |      12 |       6 
    2 |   8 |      20 |       8 
    3 |   1 |       1 |       1 
    3 |   3 |       4 |       3 
    3 |   5 |       9 |       5 
    3 |   7 |      16 |       7 
    3 |   9 |      25 |       9 
(20 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT four, ten/4 as two,
	sum(ten/4) over w as three,
	last_value(ten/4) over w
FROM (select distinct ten, four from tenk1)
WINDOW w AS (partition by four order by ten/4 rows between unbounded preceding and current row)
ORDER BY four, two, three;

 four | two | three | column3 
------+-----+-------+---------
    0 |   0 |     0 |       0 
    0 |   0 |     0 |       0 
    0 |   1 |     1 |       1 
    0 |   1 |     2 |       1 
    0 |   2 |     4 |       2 
    1 |   0 |     0 |       0 
    1 |   0 |     0 |       0 
    1 |   1 |     1 |       1 
    1 |   1 |     2 |       1 
    1 |   2 |     4 |       2 
    2 |   0 |     0 |       0 
    2 |   0 |     0 |       0 
    2 |   1 |     1 |       1 
    2 |   1 |     2 |       1 
    2 |   2 |     4 |       2 
    3 |   0 |     0 |       0 
    3 |   0 |     0 |       0 
    3 |   1 |     1 |       1 
    3 |   1 |     2 |       1 
    3 |   2 |     4 |       2 
(20 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT sum(unique1) over w,
	unique1, four
FROM tenk1 WHERE unique1 < 10
WINDOW w AS (order by unique1 rows between current row and unbounded following)
ORDER BY unique1;

 column0 | unique1 | four 
---------+---------+------
      45 |       0 |    0 
      45 |       1 |    1 
      44 |       2 |    2 
      42 |       3 |    3 
      39 |       4 |    0 
      35 |       5 |    1 
      30 |       6 |    2 
      24 |       7 |    3 
      17 |       8 |    0 
       9 |       9 |    1 
(10 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT sum(unique1) over w,
	unique1, four
FROM tenk1 WHERE unique1 < 10
WINDOW w AS (order by unique1 rows between 2 preceding and 2 following)
ORDER BY unique1;

 column0 | unique1 | four 
---------+---------+------
       3 |       0 |    0 
       6 |       1 |    1 
      10 |       2 |    2 
      15 |       3 |    3 
      20 |       4 |    0 
      25 |       5 |    1 
      30 |       6 |    2 
      35 |       7 |    3 
      30 |       8 |    0 
      24 |       9 |    1 
(10 rows)


--!syntax_v1
pragma TablePathPrefix = "/Root/stream_query_window.test_results";
pragma SimpleColumns;
SELECT sum(unique1) over w,
	unique1, four
FROM tenk1 WHERE unique1 < 10
WINDOW w AS (order by unique1 rows between 2 preceding and 2 following exclude no others)
ORDER BY unique1;

 column0 | unique1 | four 
---------+---------+------
       3 |       0 |    0 
       6 |       1 |    1 
      10 |       2 |    2 
      15 |       3 |    3 
      20 |       4 |    0 
      25 |       5 |    1 
      30 |       6 |    2 
      35 |       7 |    3 
      30 |       8 |    0 
      24 |       9 |    1 
(10 rows)


