我需要它有4个表来进行选择,并通过对每个userID
在表preds
和exact
的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子句中永远不要使用逗号。 –