i have one question about get multi rows before the date getting infection:
patientID Appt_reason dateofProcedure
1 1/2/2016
1 1/3/2016
1 infectoin 1/4/2016
2 3/1/2016
2 3/3/2016
3 3/4/2016
3 infectoin 3/5/2016
3 3/6/2016
3 3/7/2016
5 2/2/2016
5 infectoin 2/3/2016
5 2/4/2016
I need to get rows like this
patientID Appt_reason dateofProcedure
1 1/2/2016
1 1/3/2016
1 infectoin 1/4/2016
3 3/4/2016
3 infectoin 3/5/2016
5 2/2/2016
5 infectoin 2/3/2016
anybody know the answer? thanks
SELECT
patientID,
Appt_reason,
dateOfProcedure
FROM
tableName
WHERE
dateOfProcedure < '2016-04-03'
Note I'm using ISO-8601 format which is unambiguous and supported by all modern database systems.
Note that it's using the <
(less-than) operator instead of <=
(less-than-or-equal to) because in SQL a date literal value can represent datetime values, so '2016-02-01' >= '2016-02-01 01:00'
is actually false
, because '2016-02-01'
has a hidden time component equal to midnight, and 1am is after midnight.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With