how to get SUM from two different tables that are linked to third one

后端 未结 6 1359
故里飘歌
故里飘歌 2021-01-24 02:41

ok the problem is that I have to sum two sums from two tables that are linked

first table points:

id | user_id | point | hit
1  | 1       |     4 | yes
2         


        
6条回答
  •  鱼传尺愫
    2021-01-24 03:07

    maybe something like:

    select goals.user_id, sum(goal) as goal from
    (select
      user_id, point as goal from points p where  (p.hit = "yes" OR p.hit = "no") 
    union all
    select
      user_id, earning as goal from earnings) goals
    group by goals.user_id
    

提交回复
热议问题