我有这张桌子
user_id time_completed
4 86.30887
5 57.81364
5 35.50281
5 10.00000
5 74.19355
5 31.91489
6 15.00000
6 20.50000
我总结时间并将这些用户替换为另一个表(db_users):
id username country
1 admin ES
2 peter IT
3 tom US
4 user GB
5 joey GE
6 helen FR
但我也需要国家行:
user_id time_completed country
joey 209.42489 GE
user 86.30887 GB
helen 35.50000 FR
答案 0 :(得分:3)
您只需添加该字段:
SELECT b.username, SUM(time_COmpleted) totalTime, b.country
FROM tableName a
INNER JOIN db_users b
ON (a.user_id = b.id)
GROUP BY b.username, b.country
答案 1 :(得分:1)
此处,仅添加缺少的字段
SELECT b.username, SUM(time_COmpleted) totalTime, b.country
FROM tableName a
INNER JOIN db_users b
ON (a.user_id = b.id)
GROUP BY b.username, b.country
根据您的演示,所有用户都在[{1}}
上答案 2 :(得分:0)
好吧,只需将国家/地区添加到SELECT
:
SELECT b.username, SUM(time_COmpleted) totalTime, b.country
FROM tableName a
INNER JOIN db_users b
ON (a.user_id = b.id)
GROUP BY b.username