0
我想知道如果有可能寫出像這樣一個Rails的Active Record的幫手非常複雜的SQL(號將變量後代替)數:複雜的SQL與多個內部聯接和與軌
SELECT
photographs.id,
(COUNT(distinct comments.id)/50.0 * 100 * 0.25) + (15 * 0.1) + (COUNT(distinct likes.id)/100.0 * 100 * 0.05) +(COUNT(distinct likes.id)/COUNT(distinct views.id) * 100 * 0.4) +(COUNT(distinct likes.id) * 2.4/100.0 * 0.2) AS FINAL_RANKING
FROM photographs
INNER JOIN comments
ON photographs.id = comments.photograph_id
INNER JOIN likes
ON photographs.id = likes.photograph_id
INNER JOIN views
ON photographs.id = views.photograph_id
GROUP BY photographs.id
ORDER by FINAL_RANKING DESC;
我在Rails doc上找到了更簡單的例子或簡單的多內連接,但沒有計數
你可以提供保證。你可以保證它的工作或他的錢回來! –
您現在有保證! – screenmutt
Ahahah,太棒了,它的作品,非常感謝你的幫助! – Ludovic