Select only one record for each match
Let's see if I can explain this properly.
I am (unfortunately) using Access.
I have a table as such:
Date | ResID | Med | time | emar |
___________+_________+_________+_________+________|
11/18/2010 | 72 | Aspirin | 8:00 AM | 427 |
11/19/2010 | 72 | Aspirin | 8:00 AM | 427 |
11/20/2010 | 72 | Aspirin | 8:00 AM | 427 |
11/18/2010 | 72 | Aspirin | 2:00 PM | 427 |
11/19/2010 | 72 | Aspirin | 2:00 PM | 427 |
11/20/2010 | 72 | Aspirin | 2:00 PM | 427 |
11/18/2010 | 73开发者_StackOverflow | Aspirin | 7:00 AM | 428 |
11/19/2010 | 73 | Aspirin | 7:00 AM | 428 |
...etc
I know this could be set up much better, but unfortunately this is all I have with which to work.
How could I query this database such that it would return only one row for each matching set of ResID, Med, Time and emar? So the result I'm looking for from this example would be:
Date | ResID | Med | time | emar |
___________+_________+_________+_________+________|
11/18/2010 | 72 | Aspirin | 8:00 AM | 427 |
11/18/2010 | 72 | Aspirin | 2:00 PM | 427 |
11/18/2010 | 73 | Aspirin | 7:00 AM | 428 |
The date doesn't matter except that it must be in a specified range: date_min
to date_max
. This is in ColdFusion if it makes a difference.
SELECT MIN(Date) AS Date, ResID, Med, time, emar
from YourTable
WHERE Date > date_min and Date < date_max /*Might need >= and <= if inclusive*/
GROUP BY ResID, Med, time, emar
You should write something like:
Select * from TABLENAME where date>date('xxxx-xx-xx') and date<('xxxx-xx-xx')
where it says 'xxxx-xx-xx' you should write something like 2010-11-30
精彩评论