Results 1 to 4 of 4
  1. #1
    DTK0902 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Location
    Northern Ireland
    Posts
    10

    Select Records where Value appears several times over specified period.

    Hi all,
    Recently new to this forum and so far it has been a great help in helping me and the people on here are all very informative and friendly. Got a query problem, within my database which is used for medicine management and administration, i want to be able to run a query which will return the values of the animals who have had a recorded high temperature over a specified period of time, e.g over 1 month, 3 months, 6 months and 1 year.



    Was just wondering how you set up the criteria to only select and return the animal who has had more than (say 3) enteries over that period of time.

    Regards,
    Daniel

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,945
    Do you want all the fields of record or just the animal and the count?

    If just the animal and count, do a GROUP BY (Totals). Apply criteria to the count of >=3 and include data range filter criteria.

    If you want the complete record, a little harder to do.

    A subquery is one way, review http://allenbrowne.com/subquery-01.html
    especially the example for Aggregation: Counts and totals

    Another is use of domain aggregate function (DCount, DLookup, DAvg, etc) expression, something like:
    SELECT * FROM tablename WHERE DCount("*","tablename","animalID=" & [animalID] & " AND datefield BETWEEN #" & [startdate] & "# AND #" & [enddate] & "#")>=3;
    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.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,524
    It would help to know your data structure, but it might be as simple as:

    SELECT Animal, Count(Temp) AS HowHot
    FROM TableName
    WHERE Temp > 98.6
    GROUP BY Animal
    HAVING Count(Temp) > 2

    Edit: you'd also want your time frame restriction in there.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    DTK0902 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Location
    Northern Ireland
    Posts
    10
    Quote Originally Posted by June7 View Post
    Do you want all the fields of record or just the animal and the count?

    If just the animal and count, do a GROUP BY (Totals). Apply criteria to the count of >=3 and include data range filter criteria.

    If you want the complete record, a little harder to do.

    A subquery is one way, review http://allenbrowne.com/subquery-01.html
    especially the example for Aggregation: Counts and totals

    Another is use of domain aggregate function (DCount, DLookup, DAvg, etc) expression, something like:
    SELECT * FROM tablename WHERE DCount("*","tablename","animalID=" & [animalID] & " AND datefield BETWEEN #" & [startdate] & "# AND #" & [enddate] & "#")>=3;
    Hi June,
    For this I would be looking All Animals returned who have had a temperature recorded multiple times over a defined period. This would be beneficial for us in identifying animals with on-going health issues and enable us to be better informed. I will try your first recommendation of the group by, and will also look into subquery.

    I had looked at the domain aggregate function and think it could be the way forward if none of the above work.

    Regards,
    Daniel

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

Similar Threads

  1. Error 3021 appears when trying to save records...
    By curtgeo in forum Programming
    Replies: 2
    Last Post: 02-25-2012, 12:12 PM
  2. Count How Many times a value appears in a table
    By younggunnaz69 in forum Queries
    Replies: 1
    Last Post: 10-19-2011, 10:29 PM
  3. Count records between Time Period
    By turnbuk in forum Queries
    Replies: 1
    Last Post: 08-10-2011, 10:06 AM
  4. report the # of times a name appears in a field
    By rankhornjp in forum Reports
    Replies: 25
    Last Post: 08-04-2011, 01:45 PM
  5. Replies: 3
    Last Post: 08-24-2010, 07:40 PM

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