我需要它有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子句中永遠不要使用逗號。 –