Jaskowaty Jaskowaty - 7 months ago 18
SQL Question

How to SUM multiple distinct values and get max value in SQL

I'm a using distinct select in the Oracle SQL, what I want to do is sum up all the data at specific ID. Example in image:

The ouput of query now

So for example where PlayerIDFK is 1 I want to sum up TwoPointsMade in one column and ThrePointsMade in another, so for that the result would be

PlayerIDFK TwoPointsMade ThreePointsMade
--------------------------------------------------
1 5 2


The query Im using now is:

SELECT PlayerIDFK, TwoPointMade, ThreePointMade
FROM PlayerPerformance
WHERE PlayerIDFK IN (SELECT DISTINCT PlayerIDFK
FROM PlayerPerformance);

Answer

I think you could use the groupby-clause where you could group by playerIDFK and sum over twopointsmade and threepointsmade

Something like this might work:

SELECT PlayerIDFK, sum(TwoPointMade), sum(ThreePointMade) FROM PlayerPerformance GROUP BY PlayerIDFK
Comments