我想计算我对数据库中特定帖子的赞数我创建了这个简单的查询显示我对一个资源“帖子”有多少赞但是当我添加到主脚本时它会错过它
SELECT COUNT(Likes.resourceID) AS Count_resID, Resources.Id
FROM Likes INNER JOIN
Resources ON Likes.resourceID = Resources.Id
GROUP BY Resources.Id
Result
Count_resID Id
----------- -----------
1 53
2 54
2 60
2 61
1 62
(5 row(s) affected)
SELECT a.Id, a.summary, a.pageId, a.name, a.createdOn, COUNT(Likes.resourceID) AS Count_resID
FROM Resources AS a INNER JOIN
Topics_Resources AS b ON a.Id = b.ResourceID INNER JOIN
Skills_Resources AS c ON a.Id = c.ResourceID INNER JOIN
Types AS d ON a.typeId = d.Id INNER JOIN
Modules AS m ON a.ModuleId = m.ModuleID INNER JOIN
ContentItems AS ci ON m.ModuleID = ci.ModuleID INNER JOIN
Tabs AS t ON t.TabID = ci.TabID INNER JOIN
TabModules AS tb ON t.TabID = tb.TabID INNER JOIN
Likes ON a.Id = Likes.resourceID LEFT OUTER JOIN
HtmlText AS h ON tb.ModuleID = h.ModuleID
GROUP BY a.Id, a.summary, a.pageId, a.name, a.createdOn
Id summary pageId name createdOn Count_resID
----------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------
53 jihuih http://localhost/ideapark/testpage99.aspx jklhjk 2013-05-10 07:24:21.833 12
54 1 http://localhost/ideapark/testpage33.aspx sdvs 2013-05-09 07:24:21.833 2
60 sdvsdv http://localhost/ideapark/tesCreatedate.aspx dsvsdv 2013-05-13 07:32:13.133 8
61 newtest http://localhost/ideapark/newtest.aspx newTest 2013-05-13 10:35:08.027 2
62 sdvsdvds http://localhost/ideapark/page21.aspx svdsvs 2013-05-14 14:06:15.603 35
(5 row(s) affected)