基于userID的4个表中的MySQL SUM

时间:2016-08-29 18:22:05

标签: mysql

我是新手,我需要帮助 - 我需要根据ID在4个不同的表上进行SUM。

例如: table1.points table2.points table3.points table4.points user.userID

作为分数

我需要根据userID计算四个表中的所有点

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

yon可以使用此代码对所有点进行求和

select 
sum(a.point)
from
(select sum(point) as point from table1 where userid =1
 union all
 select sum(point) as point from table2 where userid =1
union all
  select sum(point) as point from table3 where userid =1
) a