Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Access2000: Query

Discussion in 'Information Technology' started by Arvi Laanemets, Nov 19, 2005.

  1. Arvi Laanemets

    Arvi Laanemets
    Expand Collapse
    Guest

    Hi

    I have a table where routes for cars are registered
    Routes: RouteID, EndTime, CarID, ..., EndKm
    (EndKm is total mileage for particular car after route, and is entered into
    table by user)

    I have a query (p.e. Q1, which returns total mileage for every car in Routes
    table after latest
    route for every month:

    SELECT b.MonthStr, a.CarID, a.EndKm As KmX
    FROM Routes AS a, Q2 AS b
    WHERE a.EndTime= b.TimeX AND a.CarID=b.CarID;

    , where Q2:
    SELECT Format$([Routes].[EndTime],'yyyy\.mm') AS MonthStr, Routes.CarID,
    MAX(Routes.EndTime) AS TimeX
    FROM Routes
    GROUP BY Format$([Routes].[EndTime],'yyyy\.mm'), Routes.CarID;

    This all works. But I need now another column in query Q1, where starting
    mileage for those cars and months is calculated. The rules for such
    calculation are:
    - the starting mileage (Km0) will be equal to latest existing mileage
    entry in Routes table for this car from all previous months.
    - when there were no entries for this car before the month, calculation
    is made for, the Km0 equals to according mileage value from special starting
    parameters table (StartValues)

    StartValues: EntryID, CarID, Date, Km, ...
    (any car can have several entries here - it depends on date, which one is
    taken in account)

    I.e. the query Q1 must be something like
    SELECT b.MonthStr, a.CarID, <Expression> As Km0, a.EndKm As KmX
    FROM Routes AS a, Q2 AS b, ...
    WHERE a.EndTime= b.TimeX AND a.CarID=b.CarID ...;


    Has anyone some idea for best way to achieve this?
    Thanks in advance!
    Arvi Laanemets
     
  2. Loading...

    Similar Threads Forum Date
    Query about Jhatka Meat by Shooting in Head Sikh Sikhi Sikhism Aug 26, 2011
    Who is a sikh? A non sikh friend's query!! Sikh Sikhi Sikhism Apr 30, 2010
    General Query Hard Talk Sep 4, 2008
    Power of pauri's in Japji Sahib query Sikh Sikhi Sikhism Aug 17, 2006
    Sikhism a query Book Reviews & Editorials Aug 2, 2005

Share This Page