rzt
02-04-2010, 01:21 AM
I'm not sure where to start here, I have a table with the fields “GoatID”, “DateWeighed” and “Weight” which is populated as follows
GoatA, 01/01/2010, 5
GoatB, 01/01/2010, 3.6
GoatC, 02/01/2010, 4
GoatB, 10/01/2010, 7.5
GoatA, 21/01/2010, 11
GoatC, 22/01/2010, 9.5
GoatD, 22/01/2010, 2.4
GoatB, 30/01/2010, 12
There are two queries that I would like to make:
1. A query that returns the most recent weight of the goats as follows
“GoatID”, “RecentDateWeighed”, “RecentWeight”
GoatA, 21/01/2010, 11
GoatB, 30/01/2010, 12
GoatC, 22/01/2010, 9.5
GoatD, 22/01/2010, 2.4
I suspect this has a relatively simple answer that has been detailed in another thread, if you can point me to it, that would be great.
2. From the second query I would like to get the “Average daily weight gain since previous weighing (DWG)”. Where DWG=(Difference in weight)/(Number of days between weighing), and Null if the goat is yet to be weighed twice.
So for the above data the result would be as follows:
“GoatID”, “DateWeighed”, “Weight”, “DWG”
GoatA, 01/01/2010, 5,
GoatA, 21/01/2010, 11, 0.3 {=6/20}
GoatB, 01/01/2010, 3.5,
GoatB, 10/01/2010, 7.5, 0.44 {=4/9}
GoatB, 30/01/2010, 12, 0.225 {=4.5/20}
GoatC, 02/01/2010, 4,
GoatC, 22/01/2010, 9.5, 0.28 {=5.5/20}
GoatD, 22/01/2010, 2.4,
I have used the “datediff” operation before but I don’t know how I could possibly implement it here. I’m just getting started in access so I may not have even set up the initial tables as would be required to return this type of information.
Any advice or suggestions are much appreciated.
GoatA, 01/01/2010, 5
GoatB, 01/01/2010, 3.6
GoatC, 02/01/2010, 4
GoatB, 10/01/2010, 7.5
GoatA, 21/01/2010, 11
GoatC, 22/01/2010, 9.5
GoatD, 22/01/2010, 2.4
GoatB, 30/01/2010, 12
There are two queries that I would like to make:
1. A query that returns the most recent weight of the goats as follows
“GoatID”, “RecentDateWeighed”, “RecentWeight”
GoatA, 21/01/2010, 11
GoatB, 30/01/2010, 12
GoatC, 22/01/2010, 9.5
GoatD, 22/01/2010, 2.4
I suspect this has a relatively simple answer that has been detailed in another thread, if you can point me to it, that would be great.
2. From the second query I would like to get the “Average daily weight gain since previous weighing (DWG)”. Where DWG=(Difference in weight)/(Number of days between weighing), and Null if the goat is yet to be weighed twice.
So for the above data the result would be as follows:
“GoatID”, “DateWeighed”, “Weight”, “DWG”
GoatA, 01/01/2010, 5,
GoatA, 21/01/2010, 11, 0.3 {=6/20}
GoatB, 01/01/2010, 3.5,
GoatB, 10/01/2010, 7.5, 0.44 {=4/9}
GoatB, 30/01/2010, 12, 0.225 {=4.5/20}
GoatC, 02/01/2010, 4,
GoatC, 22/01/2010, 9.5, 0.28 {=5.5/20}
GoatD, 22/01/2010, 2.4,
I have used the “datediff” operation before but I don’t know how I could possibly implement it here. I’m just getting started in access so I may not have even set up the initial tables as would be required to return this type of information.
Any advice or suggestions are much appreciated.