SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Query question

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Query question

    Hello,

    There's something i'd like to do but I don't know if it's possible. Imagine I have the following results for a query:

    Code:
    ----------------
    | year | value |
    ----------------
    | 2006 | 90    |
    | 2007 | 110   |
    | 2008 | 105   |
    | 2009 | 130   |
    ----------------
    I want to add a "difference" column to the results. This difference is the difference between the value for the current year and the year before. Like this:

    Code:
    ----------------------
    | year | value | dif |
    ----------------------
    | 2006 | 90    | 0   |
    | 2007 | 110   | 20  |
    | 2008 | 105   | -5  |
    | 2009 | 130   | 25  |
    ----------------------
    I'm trying to do this, but with much success.

    Thanks

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    pls show the query that produced the results
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

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