22,209
社区成员
发帖
与我相关
我的任务
分享
select
A.*,
Answer=isnull((select top 1 Answer from Answer b where B.QuestionID=a.id order by isBest DESC, QuestionID),'')
from Question A
select *,
isnull(
(select Answer from Answer where QuestionID=a.id and isBest=1)
,
isnull((select top 1 Answer from Answer where QuestionID=a.id order by QuestionID),'')
) Answer
from Question a
select a.id,a.question,isnull(b.Answer,'') 'Answer'
from Question a
left join
(select * from Answer where isBest=1) b on a.id=b.QuestionID