Operations on different rows
The following is an example of performing an operation on values in different rows of the same table:
Example 2:
In this example, the difference in STOCKQTY for products for which ITMNO is consecutive in the
STOCK table is obtained. The data to be fetched is ITMNO for both products, PRODUCT for the one
with the higher ITMNO, and the difference in STOCKQTY.
SELECT T2. ITMNO, T1. ITMNO, T2.PRODUCT, T2.STOCKQTY - T1.STOCKQTY AS STOCKQTYDIFER
FROM STOCKS. STOCK AS T1, STOCKS. STOCK AS T2
WHERE T2. ITMNO = T1. ITMNO + 1
66