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