Results 1 to 6 of 6
  1. #1
    Join Date
    May 2009
    Posts
    8

    Post Unanswered: subtraction.....need help

    there is a table named changegroup and this table contains columns as
    id and created

    id is some key and created contains timestamp

    i want to perform subtraction of two time stamps

    so the querry i wrote is

    select created from changegroup where id='10161' except
    select createf from changegroup where id ='10160'

    but this query is not giving me expected output
    so how do i perform the substraction

  2. #2
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Quote Originally Posted by ron87
    select created from changegroup where id='10161' except
    select createf from changegroup where id ='10160'

    but this query is not giving me expected output
    so how do i perform the substraction
    How should we know what your expected output is?

    Post the table definition
    Post sample data
    Post the expected result

  3. #3
    Join Date
    May 2009
    Posts
    8
    consider there are velues in created column as some integer i just want to perform subtraction of them
    table definition i have already posted plz read carefully

  4. #4
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Quote Originally Posted by ron87
    consider there are velues in created column as some integer i just want to perform subtraction of them
    So created is an integer column?

    I though it was a date column.
    That's the reason you should post the table definition

    EXCEPT is the opposite of UNION and works on a set of rows so you are on a completely wrong track.

    Let me show you what I'd like you to post:

    Sample data:
    Code:
    id     created   createf
    10161    100      200
    10160     50      120
    Expected output is: ?????

  5. #5
    Join Date
    May 2009
    Posts
    8
    if the data is like
    id created
    1 100
    2 50

    i want the subtraction of 100-50
    how can i do that

  6. #6
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Code:
    SELECT a.created - b.createf
    FROM changegroup a, changegroup b
    WHERE a.id = 10161
      AND b.id = 10160
    This will only work correctly if id is the primary key for that table

Posting Permissions

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