SELECT *, IF(start_date < ".$twoDaysAgo.", (posts/172800 * 50000), (posts/(".$curTime." - start_date) * 50000)) as rating
FROM
(
SELECT t1.*, t2.*, count(t2.id) as posts
FROM topics as t1
LEFT JOIN
(
SELECT id, topic_id as tid, poster, body, post_date, poster_ip, subject
FROM messages t9
) as t2
ON t1.topic_id = t2.tid
GROUP BY t1.topic_id
) as t3
ORDER BY rating DESC, topic_id ASC
posts列給出主題的alltime-postcounts。沒關係,我想要。但我還想在最近2天內獲得主題'postcounts'。換句話說,我需要在一個查詢中獲得主題「alltime-postcounts」和「2-day-postcounts」。一個複雜的選擇查詢
表主題: topics http://easycaptures.com/fs/uploaded/802/8788454634.png
臺消息: messages http://easycaptures.com/fs/uploaded/802/8788454634.png
請添加一些數據示例以及該數據所需的結果。幫助你會容易得多。 –
@JorgeCampos新增 – Wellenbrecher
看來MarcB已經回答了你。看看它是否有效。 –