【发布时间】:2017-03-12 13:31:07
【问题描述】:
我需要执行一个包含 4 个表的 Select,并通过将表 preds 和 exact 中每个 userID 的 reward 值相加来获得前 5 个分数:
-----table------columns-----
1. tbl_users - `userID`
2. matches - `id` (there are other columns I use for the clauses)
3. preds - `uid` (same as `userID`)
`mid` (same as `matches.id`)
`reward` (this is the column I need to sum up)
4. exact - same structure as `preds`
这是我一直在想的:
SELECT (
select sum(preds.reward) FROM preds, matches, tbl_users WHERE ...some clauses...
) a,
(
select sum(exact.reward) FROM exact, matches, tbl_users WHERE ...some clauses...
) b,
...here I need to sum(a+b) as total...,
tbl_users.userID
FROM
tbl_users
GROUP BY userID
ORDER BY total DESC LIMIT 5
【问题讨论】:
-
您有问题吗?我建议您从不在
FROM子句中使用逗号。