Re: Difference within a field between records
From: --CELKO-- <71062.1056_at_compuserve.com>
Date: 20 Jan 2002 19:21:05 -0800
Message-ID: <c0d87ec0.0201201921.ed56444_at_posting.google.com>
Date: 20 Jan 2002 19:21:05 -0800
Message-ID: <c0d87ec0.0201201921.ed56444_at_posting.google.com>
CREATE TABLE Foobar
SELECT F1.week_nbr, F1.tank_id, F1.mass,
I am making a lot of assumptions about NULLs, keys, constraints, week
numbering, etc. because you did not bother to post DDL or clear specs.
(week_nbr INTEGER NOT NULL,
tank_id INTEGER NOT NULL,
mass INTEGER NOT NULL,
PRIMARY KEY (week_nbr, tank_id));
(SELECT F2.mass
FROM Foobar AS F2
WHERE F1.tank_id = F2.tank_id
AND F1.week_nbr = F2.week_nbr + 1) - F1.mass
FROM Foobar AS F1;