I am working on fish growth rates so I need to pull weight and date for each time a single fish was measured.
Right now each capture record is on a separate line. I basically want to pull pitcode
, species
, tagdate1
, length1
, weight1
, tagdate2
, length2
, weight2
, tagdate3
, etc.. from this table, grouped by pitcode
and sorted by tagdate
. I'm using Microsoft Access. Thank you in advance for any suggestions.
pitcode tagdate length weight species
3D9.1C2D9C7FCE 7/26/2011 213 118 3
3D9.1C2D9F3AB2 7/26/2011 148 38 3
3D9.1C2D9F1627 7/26/2011 215 116 3
3D9.1C2D60CDC6 7/26/2011 165 58 3
3D9.1C2D9F0797 7/26/2011 244 204 3
3D9.1C2D9BA47F 7/26/2011 143 47 3
3D9.1C2D9FD674 7/27/2011 226 183 3
3D9.1C2DA1C597 7/27/2011 123 27.2 3
3D9.1C2D9FE09F 7/27/2011 241 182.3 3
3D9.1C2D9FE4D8 7/27/2011 286 301 3
I found this "self join" from another post, and it works:
SELECT
a.pitcode,
MIN(a.tagdate) AS td1, MIN(b.tagdate) AS td2,
MIN(a.weight) AS wt1, MIN(b.weight) AS wt2
FROM
tagd a
LEFT JOIN tagd b
ON a.pitcode = b.pitcode AND b.tagdate > a.tagdate and b.weight>a.weight
GROUP BY
a.pitcode;