sqlite/test/window4.tcl
dan ec891fd40c Add implementation of nth_value() window function.
FossilOrigin-Name: eb1fb420ac70857e7ca4cbad78be15a27bee8f915ba2da080c7efa1879c06c31
2018-06-06 20:51:02 +00:00

69 lines
1.9 KiB
Tcl

# 2018 May 19
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
source [file join [file dirname $argv0] pg_common.tcl]
#=========================================================================
start_test window4 "2018 June 04"
execsql_test 1.0 {
DROP TABLE IF EXISTS t3;
CREATE TABLE t3(a TEXT PRIMARY KEY);
INSERT INTO t3 VALUES('a'), ('b'), ('c'), ('d'), ('e');
INSERT INTO t3 VALUES('f'), ('g'), ('h'), ('i'), ('j');
}
for {set i 1} {$i < 20} {incr i} {
execsql_test 1.$i "SELECT a, ntile($i) OVER (ORDER BY a) FROM t3"
}
execsql_test 2.0 {
DROP TABLE IF EXISTS t4;
CREATE TABLE t4(a INTEGER PRIMARY KEY, b TEXT, c INTEGER);
INSERT INTO t4 VALUES(1, 'A', 9);
INSERT INTO t4 VALUES(2, 'B', 3);
INSERT INTO t4 VALUES(3, 'C', 2);
INSERT INTO t4 VALUES(4, 'D', 10);
INSERT INTO t4 VALUES(5, 'E', 5);
INSERT INTO t4 VALUES(6, 'F', 1);
INSERT INTO t4 VALUES(7, 'G', 1);
INSERT INTO t4 VALUES(8, 'H', 2);
INSERT INTO t4 VALUES(9, 'I', 10);
INSERT INTO t4 VALUES(10, 'J', 4);
}
execsql_test 2.1 {
SELECT a, nth_value(b, c) OVER (ORDER BY a) FROM t4
}
execsql_test 3.0 {
DROP TABLE IF EXISTS t5;
CREATE TABLE t5(a INTEGER PRIMARY KEY, b TEXT, c TEXT, d INTEGER);
INSERT INTO t5 VALUES(1, 'A', 'one', 5);
INSERT INTO t5 VALUES(2, 'B', 'two', 4);
INSERT INTO t5 VALUES(3, 'A', 'three', 3);
INSERT INTO t5 VALUES(4, 'B', 'four', 2);
INSERT INTO t5 VALUES(5, 'A', 'five', 1);
}
execsql_test 3.1 {
SELECT a, nth_value(c, d) OVER (ORDER BY b) FROM t5
}
execsql_test 3.2 {
SELECT a, nth_value(c, d) OVER (PARTITION BY b ORDER BY a) FROM t5
}
finish_test