Skip to content
Advertisement

Get row Sums across multiple users/tables

I am working in SQL Server, and I have three tables that I have simplified below

USERS:

POINTS:

CLAIMS:

I’m trying to run a report of distinct users with a sum of points earned and a sum of points used. I’ve started with the join of tables by userId…

but of course that returns the user multiple times, I’ve tried many variations of Group By, Distinct, etc but can’t seem to get there. Users are (in theory) already distinct by Id or email, the entries into the other two tables are dozens up to hundreds per user.

Desired output would be something like this

Any help is appreciated.

Advertisement

Answer

Try it with subqueries and LEFT JOINS in case there are Users without points.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement