這裏是我的表結構:如何根據特定時期的聲譽來選擇用戶?
-- users
+----+--------+--------------------+
| id | name | other columns ...
+----+--------+--------------------+
-- votes
+----+---------+---------+-------+------------+
| id | user_id | post_id | value | date_time |
+----+---------+---------+-------+------------+
| 1 | 234234 | 3443 | 1 | 1442684886 | -- For example
+----+---------+---------+-------+------------+
我想在上週選擇前20名用戶。我怎樣才能做到這一點?
這裏是我當前的查詢:
SELECT SUM(v.value) score , u.*
FROM users u
INNER JOIN votes
ON u.id = v.user_id
WHERE v.date_time > UNIX_TIMESTAMP(now() - INTERVAL 1 week)
ORDER BY score DESC
LIMIT 20;
但我的查詢返回只有一行。
見https://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a-very -simple-sql-query – Strawberry