Results 1 to 6 of 6
  1. #1
    ClimateGuy is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    3

    Extract minimum temperature readings for a specified range

    Hi there,




    I have the following table in an access dbase (refer to sample attachment) that holds temperature measurements (at ten minute intervals) from a series or weather stations. The table is described below:


    FIELD, DESC
    id, weather station id
    temp, temperature reading of weather station
    date_time, date/time field (read as: dd/mm/yyyy hh:mm)


    I need to construct a query to extract the minimum temperature between the times 9.00am to 8.50am the following day (i.e. a 23hr50min range) for each day (or range) for each weather station. FYI each station (80 in total) has 5 months worth of ten minute temperature readings from 1/08/2011 to 30/11/2011. Can anyone help with this query for i can't figure this one out?
    Attached Files Attached Files

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Create a query that returns those 3 fields plus a new one along the lines of:

    CalcDate: IIf(TimeValue(date_time)<#9:00:00 AM#,DateValue(DateAdd("d",-1,date_time)),DateValue(date_time))

    That should give you a calculated field that returns the current date for records starting at 9, the previous date for the earlier records. You can group on that field in a totals query to get the minimum temperature. If you also need the time, this type of thing:

    http://www.baldyweb.com/LastValue.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    EDIT: Did not see pbaldy's suggestion before I posted so dumped my comments after testing his and discovering it does indeed work.

    SELECT Min(Table1.temp) AS MinOftemp, IIf(TimeValue([date_time])<#12/30/1899 9:0:0#,DateValue(DateAdd("d",-1,[date_time])),DateValue([date_time])) AS CalcDate
    FROM Table1
    GROUP BY IIf(TimeValue([date_time])<#12/30/1899 9:0:0#,DateValue(DateAdd("d",-1,[date_time])),DateValue([date_time]));


    However, dates in dd/mm/yyyy instead of Access mm/dd/yyyy convention might give you grief. Review this http://allenbrowne.com/ser-36.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    ClimateGuy is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    3
    Thank you guys! This is exactly what i needed.

    One more thing, if i needed to extract average temperature for every hour for each each station, what would be the query for this? As you may gather, i struggle writing aggregation queries that have anything to do with date/time.

    Once again thanks!

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    See if this is what you want:
    SELECT Avg(temp) AS AvgOftemp, ID, DateValue([date_time]) AS ReadDate, Hour([date_time]) AS ReadHour
    FROM Table1
    GROUP BY ID, DateValue([date_time]), Hour([date_time]);
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    ClimateGuy is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    3
    Thanks June 7! Perfect. I appreciate your help

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Criteria for a minimum itself
    By hawkins in forum Access
    Replies: 17
    Last Post: 07-27-2011, 12:57 PM
  2. Querying the "minimum value" record
    By LunaticFringe82 in forum Queries
    Replies: 1
    Last Post: 06-02-2011, 04:10 PM
  3. one-to-many-or-none table relationship? (minimum cardinality)
    By racecar333 in forum Database Design
    Replies: 2
    Last Post: 02-24-2011, 07:11 AM
  4. Can't see minimum or maximum buttons?!?
    By Felix_too in forum Forms
    Replies: 2
    Last Post: 12-29-2010, 10:04 AM
  5. Replies: 2
    Last Post: 11-25-2010, 11:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums