我正在處理一個查詢,該查詢正在連接多個表以進行深入分析,以獲取訂閱者投票次數超過一個區域的訂閱者數量。MySQL選擇行大於1的行
我被困在的問題是試圖在查詢中計算訂閱者投票超過一個的計算。
SELECT COUNT(*), regions.name,
(SELECT COUNT(*) FROM votes
LEFT JOIN profiles on votes.subscriber_id = profiles.subscriber_id
LEFT JOIN countries on profiles.country_id = countries.id
WHERE countries.region_id = regions.id GROUP BY votes.subscriber_id) as vote_count
FROM subscribers
LEFT JOIN profiles on subscribers.id = profiles.subscriber_id
LEFT JOIN countries on profiles.country_id = countries.id
LEFT JOIN regions on countries.region_id = regions.id
LEFT JOIN votes on subscribers.id = votes.subscriber_id
WHERE subscribers.created_at < '2011-04-22 00:00:00'
GROUP BY regions.id
HAVING vote_count > 1;
隨着我得到的錯誤上面的查詢,Subquery returns more than 1 row
任何想法?
你能更清楚地解釋你要找的是什麼號碼嗎?如果子查詢不能保證返回單個行,這將始終給出錯誤,因爲它期望子查詢中的字段名稱。 – Mel 2011-05-11 20:16:54