表一:first
id grade
1 20
2 19
表二:second
id grade
1 18
3 19
表三:third
id grade
1 20
4 17
本人想合并成表四:sum
id grade
1 58
2 19
3 19
4 17
有什么办法吗?sql语句不精通,求帮助……
id grade
1 20
2 19
表二:second
id grade
1 18
3 19
表三:third
id grade
1 20
4 17
本人想合并成表四:sum
id grade
1 58
2 19
3 19
4 17
有什么办法吗?sql语句不精通,求帮助……
解决方案
40
select id,sum(grade) from( select id ,grade from first union all select id ,grade from second union all select id ,grade from third union all ) t group by id