# # Test LAST_VALUE() Window Function # Author: Bharath, bharath.bokka@mariadb.com # -- source ../include/have_columnstore.inc --disable_warnings DROP DATABASE IF EXISTS mcs127_db; --enable_warnings CREATE DATABASE mcs127_db; USE mcs127_db; CREATE TABLE t1 (a CHAR(1), b INT)ENGINE=Columnstore; INSERT INTO t1 VALUES ('', NULL),('a', 123),('a', 1),('b', 123),('c', 1861),('c', 1991),('d', 10701),('d', 1071),('a', 92); SELECT a, b, LAST_VALUE(b) OVER(ORDER BY a) last_value FROM t1; SELECT a, b, LAST_VALUE(b) OVER(ORDER BY b DESC) last_value FROM t1; SELECT a, b, LAST_VALUE(a) OVER(ORDER BY b) last_value FROM t1; SELECT a, b, LAST_VALUE(b) OVER(ORDER BY a DESC) last_value FROM t1; SELECT a, b, LAST_VALUE(a) OVER w last_value FROM t1 WINDOW w AS (ORDER BY a DESC); SELECT a, b, LAST_VALUE(b) OVER w last_value FROM t1 WINDOW w AS (ORDER BY b); SELECT a, b, LAST_VALUE(b) OVER(PARTITION BY b) last_value FROM t1; SELECT a, b, LAST_VALUE(b) OVER(PARTITION BY a) last_value FROM t1; SELECT a, b, LAST_VALUE(a) OVER(ORDER BY b RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) last_value FROM t1; SELECT a, b, LAST_VALUE(b) OVER(ORDER BY b RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) last_value FROM t1; SELECT a, b, LAST_VALUE(b) OVER(PARTITION BY b ORDER BY b DESC RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) last_value FROM t1; SELECT a, b, LAST_VALUE(a) OVER(PARTITION BY b ORDER BY b DESC RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) last_value FROM t1; SELECT a, b, LAST_VALUE(b) OVER(PARTITION BY a ORDER BY b DESC RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) last_value FROM t1; --error ER_WRONG_TYPE_FOR_RANGE_FRAME SELECT a, b, LAST_VALUE(b) OVER(PARTITION BY a ORDER BY a DESC RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) last_value FROM t1; --error ER_WRONG_TYPE_FOR_RANGE_FRAME SELECT a, b, LAST_VALUE(b) OVER(PARTITION BY b ORDER BY a DESC RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) last_value FROM t1; # Clean UP DROP DATABASE mcs127_db;