20分
#1 |
select id,title,context,(select count(1) from reply where articleId=@id) as cnt from article where id=@articleId
|
10分
#2 |
上面@id和@articleId写错,看成一个id好了
|
10分
#3 |
SELECT a.*,ISNULL(replyCount,0) AS replyCount FROM article a WITH(NOLOCK) LEFT JOIN( SELECT articleid,COUNT(0) AS replyCount FROM reply b WITH(NOLOCK) GROUP BY articleid ) t ON a.id = t.articleid |