0

以下是我的表:

PatientID|VisitID|Date|Accident|Diagnosis|Doctor
  1      |    1  |    |        |         | 
  1      |    2  |    |        |         |
  1      |    3  |    |        |         |

PatientID和都是VisitID复合主键。现在我只想显示最后一条记录。换句话说,其中PatientID=1VisitID= 最大值。

那么查询会是什么?

4

2 回答 2

0

我办公室的一位前辈告诉了以下问题,这完全符合我的目标。

select * 
  from tblAccident 
 where PatientID = 1 
   and VisitNo = ( Select Max(VisitNo) from tblAccident where PatientID = 1 )
于 2012-07-02T10:08:51.890 回答
0

假设这VisitID是顺序的:

select top 1 * from yourTable
where PatientID=@patientID
order by VisitID desc

其中:@patientID是一个参数(在您的示例中是1

于 2012-06-13T05:49:04.663 回答