Counting events in a query

  • Thread starter Thread starter Tom Tripicchio
  • Start date Start date
T

Tom Tripicchio

I have dates for each time a patient was seen. Is there a way to write a
query that will give me the first 2 dates of each patient?

Examples
Patient 1) 9/1, 9/3, 9/5, 9/9, 9/10
Patient 2) 9/5,9/7, 9/9, 9/10, 9/11

Can the query return patient 1) 9/1, 9/3, and patient 2) 9/5,9/7? I want to
cross reference this with what the patient must have done by the first 2
visits.

Thanks, Tom
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Perhaps this:

SELECT PatID, VisitDate
FROM table_name As A
WHERE VisitDate IN (SELECT TOP 2 VisitDate FROM table_name
WHERE PatID = A.PatID ORDER BY VisitDate)
ORDER BY PatID, VisitDate

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQYgrs4echKqOuFEgEQJ7dwCcCYBBbxrNTiGVvL3zdI0gVzhomVEAn1cg
uFCdAKftEKd8iQtXpsa7Gtol
=8Z6Z
-----END PGP SIGNATURE-----
 
Do you have table structures you would like to share? From what you have
stated you want, I doubt the results will be of any help to "cross reference
this with what the patient must have done by the first 2 visits".
 
There are 2 tables, patients which has all demographic info and an "events"
tables that has all of the visit dates and what was done at each visit. They
are linked by a "case #".

Thanks for your help.
 
I will give that a try, thanks.
MGFoster said:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Perhaps this:

SELECT PatID, VisitDate
FROM table_name As A
WHERE VisitDate IN (SELECT TOP 2 VisitDate FROM table_name
WHERE PatID = A.PatID ORDER BY VisitDate)
ORDER BY PatID, VisitDate

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQYgrs4echKqOuFEgEQJ7dwCcCYBBbxrNTiGVvL3zdI0gVzhomVEAn1cg
uFCdAKftEKd8iQtXpsa7Gtol
=8Z6Z
-----END PGP SIGNATURE-----
 
Back
Top