SELECT partnum,
LAG(partnum) OVER w AS 'prev_partnum',
partnum - LAG(partnum) OVER w AS 'diff'
FROM nspcl
WINDOW w AS (ORDER BY id);
SELECT
t2.partnum p2,
t1.partnum p1,
t2.partnum - t1.partnum res
FROM nspcl t1
INNER JOIN nspcl t2 ON t1.id = (t2.id - 1)
SELECT t1.num, t2.num, t2.num-t1.num
FROM
(
SELECT num,
ROW_NUMBER() OVER(ORDER BY num) AS rn
FROM table
) AS t1
LEFT JOIN
(
SELECT num,
ROW_NUMBER() OVER(ORDER BY num) AS rn
FROM table
) AS t2
ON t1.rn=t2.rn-1
"два конца, два кольца, по-середине - гвоздик" - "очки фраеру прибили"