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 | 1 | 2 | yes
3 | 1 | -3 | no
4 | 1 | 4 | mb
5 | 2 | 2 | yes
6 | 2 | -3 | no
7 | 2 | 4 | mb
seccond table earnings:
id | user_id | earning
1 | 1 | 5
2 | 1 | 2
3 | 1 | 3
4 | 1 | 4
5 | 2 | 2
6 | 2 | 3
7 | 2 | 4
now what I’ve tried is this:
SELECT
p.id,
SUM( SUM(p.point) + SUM(e.earning) ) AS bb
FROM
points p LEFT JOIN earnings e ON p.user_id = e.user_id
WHERE
(p.hit = "yes" OR p.hit = "no")
GROUP BY
p.user_id
but I got wrong results
I want to get this:
id | bb
1 | 17
2 | 8
Thanks!
If you want total earnings per user, you should probably start by identifying which users you want earnings for. The most sensible option is probably to use the users table itself as the basis.
This approach has the added benefit of reporting on users who had no points and/or earnings.