Teradata: if field is not null, add next two rows of specific column to total <p>Hi everyone - </p> <pre><code>ID TOTAL QTY 111 NULL 100 112 NULL 150 113 312.00 70 114 NULL 200 115 14.00 40 116 NULL 70 117 NULL 100 118 NULL 170 </code></pre> <p>I'm trying to figure something relatively complicated out using Teradata. In the data above, I want to create a new column called THREEDAY. If TOTAL is null, then I want THREEDAY to equal the amount in QTY. If TOTAL is not null, however, I want TOTAL to equal the amount in QTY <strong>plus</strong> the amount in QTY for the following two rows. For example: </p> <pre><code>ID TOTAL QTY THREEDAY 111 NULL 100 100 112 NULL 150 150 113 312.00 70 310 114 NULL 200 200 115 14.00 40 210 116 NULL 70 70 117 NULL 100 100 118 NULL 170 170 </code></pre> <p>For ID 113, the amount in THREEDAY is 310 (70+200+40), and for ID 115, the amount is 210 (40+70+100). For the rest of the IDs, the amount in THREEDAY equals QTY because the value in TOTAL is missing.</p> <p>My skills are not up to par to tackle this kind of problem, so any assistance would be great. Thanks!</p>