Home  >  Article  >  Backend Development  >  问个连表的MYSQL查询语句解决方案

问个连表的MYSQL查询语句解决方案

WBOY
WBOYOriginal
2016-06-13 12:12:59830browse

问个连表的MYSQL查询语句

假如
表1
id    name 
1       A
2       B

表2
id    money
1         10
1          15
2          20
1          10

如何用左链表的方式,获得如下结果呢

1     A     40
2     B     20

------解决思路----------------------
select a.*, sum(money) as money from 表1 a left join 表2 b on a.id=b.id

1     A     45
2     B     20

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn