Thread: Rest dates

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Substract dates


    Hi there.

    I have a table where are stored some values such as:

    Id, Mobile, Speed, DateTime
    175080, 1886, 40, 2012-10-03 08:07:56
    175081, 2470, 75, 2012-10-03 08:08:48
    175082, 1886, 0, 2012-10-03 08:10:59
    175083, 1886, 20, 2012-10-03 08:12:59

    And I used to use a query for substracting these dates and then get the difference between two times:

    SELECT f.id, f.mobile, f.DateTime as StardDate, f2.DateTime as EndDate,
    (f.DateTime -f2.DateTime) AS difference
    FROM table f, table f2
    where f2.id = f.id-1
    and f.mobile=1886
    order by f.DateTime desc

    The problem is that previouly I only have one mobile and now I have more.

    How can I just substract the dates of the mobile 1886 ?

    Best regards.
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,026
    Rep Power
    4210
    this idea of joining on id = id - 1 is flawed
    r937.com | rudy.ca
    please visit Simply SQL and buy my book

IMN logo majestic logo threadwatch logo seochat tools logo