我正在尝试对这样的两个表进行排序:
1 | Gang 1 | Total wealth: $100,000
2 | Gang 2 | Total wealth: $97,000
帮派结构(“帮派”):
gangID,gangName
玩家结构(“玩家”)
ID,用户名,帮派,金钱,银行
我想查询玩家是否在帮派中,它会将玩家Money + Bank计算为总财富。但是,我不确定如何做到这一点,我真的很喜欢你的帮助。
答案 0 :(得分:1)
这就是你需要的
select
g.gangID,
g.gangName,
concat('$ ',`tot_wealth`) as `Total wealth`
from gang g
inner join
(
select Gang,FORMAT(sum(Cash+Bank),0) as `tot_wealth`
from players
group by Gang
)p
on p.Gang = g.gangID
group by g.gangID