我不明白爲什麼這不起作用。基本上,我正在運行一個子查詢來計算p.songid WHERE trackDeleted=0
的所有行。當我自己執行它時,子查詢工作正常,但是當我實現時,我得到「子查詢返回多於一行」。MySQL子查詢返回多於一行
SELECT u.username, u.id, u.score, s.genre, s.songid, s.songTitle, s.timeSubmitted, s.userid, s.insWanted, s.bounty,
(SELECT COUNT(p.songid)
FROM songs s
LEFT JOIN users u
ON u.id = s.userid
LEFT JOIN posttracks p
ON s.songid = p.songid
WHERE p.trackDeleted=0
GROUP BY s.timeSubmitted ASC
LIMIT 25)
AS trackCount
FROM songs s
LEFT JOIN users u
ON u.id = s.userid
LEFT JOIN posttracks p
ON s.songid = p.songid
WHERE paid=1 AND s.timeSubmitted >= (CURDATE() - INTERVAL 60 DAY)
GROUP BY s.timeSubmitted ASC
LIMIT 25
我基本上試圖創建一個新的列與軌道數所有軌道WHERE deletedTrack = 0。我還會怎麼做呢? – user978905
只需從子查詢中刪除GROUP BY和LIMIT子句 –
如果我這樣做,它會爲每一行返回相同的值。我需要它能夠返回每個songid的tracksDeleted = 0的行數。 – user978905