有两个mysql表,就像table1和table2一样。我想通过一个sql得到结果。
#table1
c1 c2 //clomun
a 10
b 20
c 30
#table2
c1 c2
a 11
b 21
e 99
我想得到如下的结果。
# result
c1 c2
a 21
b 41
c 30
e 99
答案 0 :(得分:3)
这应该有效:
TextViews
请注意,如果列名不相同,则需要为它们提供相同的别名,如下所示:
select c1, sum(c2) from
(
select c1, c2 from table1
union all
select c1, c2 from table2
) as total
group by c1