开发者

How do I retrieve data from SQL server table which has two columns say PatientID and TestNo, Differnt TestNo can have same patient ID

I have a database (SQL server 2005 Express) table wth columns Pati开发者_StackOverflowentID (more than 1 records can have same patient ID) and TestNo. I want to retrieve the maximum of testNo column among all the records with same PatientID.What should be the SQL statement to do so?I am using RecordSet pointer to access the records in a vc++ application.


Use this SQL:

SELECT MAX(TestNo), PatientID
FROM dbo.YourTable
GROUP BY PatientID


The following query should do your work:

Select max(TestNo) as TestNo, PatientId from TableName group by PatientId

This will return you the max of the test no for each of the patient. You can add where condition if you need to take for a particular patient.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜