So.... we have three different tables that pertains to a contest in which the DB keeps track of how many points they've received for each contest. Contest 1, 2 and 3. Each time that user achieves something, a new row is created for that user with the additional points. So in order to calculate all the points that user has received I use a select sum
SELECT userID, SUM(amount1) as "Contest 1 Points"
FROM [Company].[dbo].[Contest1]
WHERE userid not in (0,1)
GROUP BY userId
ORDER BY userid
because I have two more contests I do a query for each of those as well...
SELECT userId, SUM(amount2)/.65 AS "Category 2 Points"
FROM [Company].[dbo].[Contest2]
WHERE dateGiven >=201301 AND dateGiven <= 201305
GROUP BY userId
ORDER BY userid
SELECT userid, SUM(amount3) AS "Category 3 Points"
FROM [Company].[dbo].[Contest3]
where userid not in (1,2)
GROUP BY userid
ORDER BY userid
I basically need to add up all the points each user receives from each contest into 1 column that basically shows results USERID, TOTAL OF TOTALS(Contest1 + Contest2 + Contest3)
or at least have it like,
USER, Contest1 Total, Contest2 Total, Contest3 Total
The way I did this so far was copy/paste each of these results into excel and then I used VLOOKUP to match them up to eachother, which was kind of a hassle and im sure theres a way to do it in SQL. Im pretty new to SQL and I've tried joining and usig ON for matching the userid but there's something wrong with my syntax and how I understand that it all plugs into itself for queries.