17.10 - 例:NULLとIGNORE NULLS - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL関数、式、および述部

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
2021年7月
Content Type
プログラミング リファレンス
Publication ID
B035-1145-171K-JPN
Language
日本語 (日本)

ANSIスタイルの構文:

SELECT empno, empname, job, sal,
       LEAD(sal, 1, 0) IGNORE NULLS
       OVER (PARTITION BY job ORDER BY empno) AS sal_next
FROM   emp
ORDER BY job, empno;

 EMPNO      EMPNAME      JOB       SAL      SAL_NEXT
---------- ---------- --------- ---------- ----------
   12        PAUL       ANALYST    ?          3000
   13        GRACE      ANALYST    3000       0
   1         JOHN       CLERK      800        950
   2         ERIC       CLERK      950        1300
   3         KURT       CLERK      ?          1300
   6         JULIE      CLERK      1300       0
   9         NICHOLAS   MANAGER    2450       2850
   10        NOVAK      MANAGER    ?          2850
   11        ROGER      MANAGER    2850       0
   14        RICH       PRESIDENT  5000       0
   4         KENT       SALESMAN   1250       1500
   5         LYNN       SALESMAN   ?          1500
   7         TERESA     SALESMAN   1500       1600
   8         MATTHEW    SALESMAN   1600       0

Teradataスタイルの構文:

SELECT empno, empname, job, sal,
       LEAD(sal IGNORE NULLS, 1, 0) 
       OVER (PARTITION BY job ORDER BY empno) AS sal_next
FROM   emp
ORDER BY job, empno;

 EMPNO      EMPNAME      JOB       SAL      SAL_NEXT
---------- ---------- --------- ---------- ----------
   12        PAUL       ANALYST    ?          3000
   13        GRACE      ANALYST    3000       0
   1         JOHN       CLERK      800        950
   2         ERIC       CLERK      950        1300
   3         KURT       CLERK      ?          1300
   6         JULIE      CLERK      1300       0
   9         NICHOLAS   MANAGER    2450       2850
   10        NOVAK      MANAGER    ?          2850
   11        ROGER      MANAGER    2850       0
   14        RICH       PRESIDENT  5000       0
   4         KENT       SALESMAN   1250       1500
   5         LYNN       SALESMAN   ?          1500
   7         TERESA     SALESMAN   1500       1600
   8         MATTHEW    SALESMAN   1600       0