求个sql查询语句
表A
id name sex
1 a1 男
2 a2 男
表B
name money
a1 1
a1 2
a2 2
a2 5
如何实现成下表:
id name sex total
1 a1 男 3
2 a2 男 7 SQL
[解决办法]
select a.id,a.name,a.sex,sum(b.money) as total
from a
left join b on a.name=b.name
group by a.id,a.name,a.sex