Select A.sendtoWhom,
sendDate = Isnull((
Select Top 1 B.sendDate From sendChat B
Where B.sendtoWhom = A.sendtoWhom
And B.sendEmail='aa@sina.com'
Order by B.sendDate Desc
),'')
From
(select distinct sendtoWhom
from sendChat
where sendEmail='aa@sina.com'
order by sendDate desc) A
对于重复项的日期,你想要哪一个?你可以先试试这个:
select sendtoWhom,'sendDate' = Max(sendDate) from sendChat
where sendEmail='aa@sina.com'
group by sendtoWhom
order by sendDate desc