Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2008
    Posts
    1

    Unanswered: need help for sql

    Hi team,
    I have a table GROWTH having column
    SERVER VARCHAR(12),
    SIZE INTEGER,
    USED INTEGER,
    REPORTDATE date

    and the data is
    Serev Size Used reportdate required O/P
    1 100 2 1/1/2008
    1 100 5 1/2/2008
    1 100 12 1/3/2008
    1 100 15 1/4/2008
    1 100 18 1/5/2008
    1 100 21 1/6/2008
    1 100 25 1/7/2008 23 difference in the week
    1 100 27 1/8/2008
    1 100 29 1/9/2008
    1 100 35 1/10/2008
    1 100 38 1/11/2008
    1 100 40 1/12/2008
    1 100 45 1/13/2008
    1 100 48 1/14/2008 21
    1 100 50 1/15/2008
    1 100 52 1/16/2008
    1 100 55 1/17/2008
    1 100 59 1/18/2008
    1 100 62 1/19/2008
    1 100 68 1/20/2008
    1 100 78 1/21/2008 28
    2 100 3 1/1/2008
    2 100 7 1/2/2008
    2 100 15 1/3/2008
    2 100 23 1/4/2008
    2 100 26 1/5/2008
    2 100 30 1/6/2008
    2 100 40 1/7/2008 37
    2 100 42 1/8/2008
    2 100 45 1/9/2008
    2 100 50 1/10/2008
    2 100 55 1/11/2008
    2 100 58 1/12/2008
    2 100 59 1/13/2008
    2 100 62 1/14/2008 20
    2 100 65 1/15/2008
    2 100 68 1/16/2008
    2 100 71 1/17/2008
    2 100 73 1/18/2008
    2 100 75 1/19/2008
    2 100 80 1/20/2008
    2 100 85 1/21/2008 20
    3 100 4 1/1/2008
    3 100 10 1/2/2008
    3 100 17 1/3/2008
    3 100 21 1/4/2008
    3 100 27 1/5/2008
    3 100 35 1/6/2008
    3 100 40 1/7/2008 36
    3 100 42 1/8/2008
    3 100 45 1/9/2008
    3 100 48 1/10/2008
    3 100 51 1/11/2008
    3 100 56 1/12/2008
    3 100 58 1/13/2008
    3 100 62 1/14/2008 20
    3 100 68 1/15/2008
    3 100 70 1/16/2008
    3 100 75 1/17/2008
    3 100 80 1/18/2008
    3 100 85 1/19/2008
    3 100 89 1/20/2008
    3 100 92 1/21/2008 24


    Need sql to find out the difference in the week. means the o/p like marked in red color.I am using DB2 UDB V7.2

    Thanks In Advance
    Anoop Jategaonkar
    Pune

  2. #2
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    Could you describe what this "difference in the week" is supposed to be? How is it calculated?

    I guess it may be USED from one Monday to the next. But I can't be sure because your sample output (if the red numbers are that) don't line up.
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

  3. #3
    Join Date
    Dec 2005
    Posts
    273
    consider joining the table with itself:

    SELECT A.SERVER , A.SIZE , A.USED , A.REPORTDATE , ( A.SIZE - B.SIZE ) AS DIFFERENCE
    FROM GROWTH A LEFT JOIN GROWTH B
    ON A.SERVER = B.SERVER
    AND A.REPORTDATE = ( B.REPORTDATE + 7 DAYS ) ;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •