我試圖執行以下查詢如何在Q&使用MySQL查詢
SELECT a.userid, COUNT(a.id) AS count_answers, SUM(v.yes_vote) as total_up_votes, SUM(v.all_vote - v.yes_vote) as total_down_votes, CAST(COUNT(a.id) + SUM(v.yes_vote) * 4 - SUM(v.all_vote) AS SIGNED) AS voting_points
FROM (answers a)
LEFT OUTER JOIN answers_vote_count v ON r.id = v.answer_id
GROUP BY a.userid
ORDER BY count_answers DESC
正如你可以看到一個網站計算投票點的,我試圖來計算回答收到的點接收。
點的計算一樣 -
- 1點每一個答案 - COUNT(答案)
- 3點在回答每一個高達票 - 3 * SUM(yes_vote)
- (-1)點每下降票 - SUM(all_vote) - SUM(yes_vote)
我的問題是 - 如果答案不具有up_vote和down_vote,點出來爲NULL。 COUNT(答案)部分無法正常工作。
什麼我做錯了在這裏?
Regards
使用'IFNULL'話,很方便;-) – zerkms 2010-10-13 05:41:56
@zerkms - 謝謝。將使用該。 – vikmalhotra 2010-10-13 06:48:26