sql多表字段求和
表1:
name point
bob 20
bob 30
mike 38
表2:
name point
bob 53
mike 15
mike 38
如上所示,表一、表二结构相同,现在想求bob表一表二point之和,即20+30+53
要求一条sql语句实现(注意只能用一条sql语句),请教高人如何实现?
------解决方案--------------------SELECT SUM(point) FROM
(SELECT [name], [point] FROM 表a
UNION ALL
SELECT [name], [point] FROM 表b) t3
GROUP BY [name]
------解决方案--------------------select AA.name,sum(AA.point) as totalP
from (
select * from t1 uion all select * from t2)
as AA
group by AA