select BlogArticle.*,BlogArticleClass.Title as ClassTitle from BlogArticle left join BlogArticleClass on BlogArticleClass.id=BlogArticle.classID
下面这段的作用是:
显示BBS中的精华内容中的前五条.
并且显示 贴子标题(BBS.Title) 昵称(UserInfo.Nickname) 头像(Userinfo.Face) 回贴数(PostCount)
SELECT TOP 5 BBS.*, UserInfo.Nickname AS Nickname, UserInfo.Face AS Face,
isnull(TEMP . COUNT, 0) AS PostCount
FROM BBS LEFT JOIN
UserInfo ON Userinfo.Username = BBS.Username LEFT JOIN
(SELECT Belong, COUNT(*) AS COUNT
FROM BBS
GROUP BY Belong) AS TEMP ON TEMP .Belong = BBS.ID
WHERE BBS.IsGreat = 1 AND BBS.Belong = 0
isnull(TEMP . COUNT, 0) AS PostCount
FROM BBS LEFT JOIN
UserInfo ON Userinfo.Username = BBS.Username LEFT JOIN
(SELECT Belong, COUNT(*) AS COUNT
FROM BBS
GROUP BY Belong) AS TEMP ON TEMP .Belong = BBS.ID
WHERE BBS.IsGreat = 1 AND BBS.Belong = 0