0
我想從3表中檢索值,我收到錯誤「子查詢返回多於1行」。MySql拋出錯誤子查詢返回多於1行
我的想法是檢索所有帖子,我必須從每個帖子計算ttpostvotes表中的投票總數,並且如果提供的userid被投票給該帖子,那麼它將顯示帖子計數爲1或 - 1。
我的查詢是如下:
SELECT r.PostId, r.`Post`,r.PostTime, coalesce(x.Votes, 0) as Votes ,
(Select Votes From `ttpostvotes` where UserId=30 and x.PostId=r.PostId) as IsUservoted,
(Select Count(*) From ttreply where PostId=r.PostId) AS ReplyCount FROM `ttpost` r
left join (SELECT PostId, sum(Votes) as Votes FROM `ttpostvotes` GROUP BY PostId) x ON
x.PostId = r.PostId WHERE r.OffensiveCount<3 and r.SpamCount<5 and r.OtherCount<7 and r.`PeekId`=101 ORDER BY `r`.`PostTime` DESC
3個表是像如下: ttpost
ttpostvotes
ttreply