Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2004
    Posts
    162

    Unanswered: sum all record except last one entered

    im trying to summarize all records except the last one entered.
    ex

    -column001-
    1
    2
    3
    4
    5
    6

    the output should be "15" (1+2+3+4+5) is this possible?

    One thing i tryed is to put in autodate and time and then count them and leaveout the newest one. Well i can't make it work...

    Thx for all help

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    no, with the example you have shown, it is not possible
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Mar 2004
    Posts
    162
    ok, if i use a colum with autonumber and leave out the highest one? like this:
    colum001, colum002
    001,1
    002,2
    003,3
    004,4
    005,5
    006,6

    the output should be:
    colum002
    15

    summirize all records except the one with the highest ID

  4. #4
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    With your sample data the only possible "solution" is:
    Code:
    SELECT sum(column001) FROM theTable WHERE column001 <> 6
    This is because (as r937 has already pointed out) your sample data does not offer any way (e.g. a column with a timestamp) to identify the "newest one".

    If you do have a timestamp column, the following could work (not tested)
    Code:
    SELECT sum(column001) 
    FROM theTable
    WHERE modification_date <> (SELECT max(modification_date) FROM theTable)
    Edit: Our posts overlapped: modification_date will be your autonumber

  5. #5
    Join Date
    Mar 2004
    Posts
    162
    ahh super... thx m8 it works like a charm... of course use MAX

Posting Permissions

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