Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> comp.databases.theory -> Re: Difference within a field between records

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@posting.google.com>


CREATE TABLE Foobar
(week_nbr INTEGER NOT NULL,
 tank_id INTEGER NOT NULL,
 mass INTEGER NOT NULL,
 PRIMARY KEY (week_nbr, tank_id));

 SELECT F1.week_nbr, F1.tank_id, F1.mass,

        (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;

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. Received on Sun Jan 20 2002 - 21:21:05 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US