DB2 OLAP – Using Window Functions for Aggregates

aggregatedb2olapwindow functions

I am using DB2 z/OS 11.1.5. According to this reference, OLAP functions such as first_value should be supported at least in DB2 9.7. However, when trying to execute the query

declare global temporary table T (reference integer, val integer) on commit preserve rows;
insert into session.T values(1, 10);
insert into session.T values(2, 20);
select first_value(val) over (order by reference) from session.T;

I am given the error

NO AUTHORIZED FIRST_VALUE NAMED HAVING COMPATIBLE ARGUMENTS WAS FOUND. SQLCODE=-440, SQLSTATE=42884, DRIVER=4.18.60. 2) [Error Code: -514, SQL State: 26501] THE CURSOR SQL_CURLH200C1 IS NOT IN A PREPARED STATE.. I am aware of the listing of error codes. However, these descriptions do not help me to understand the problem.

Best Answer

You are mixing up Db2 (Db2 for Linux, Unix and Windows) and Db2 for z/OS.

Db2 9.7 is LUW (Linux, Unix and Windows) and FIST_VALUE is available on these OS'es.

Db2 for z/OS does not support FIRST_VALUE.