365 Days of Daily Coding: Day 131
I am having a lovely day today. I just started this awesome LinkedIn trend called #LinkedInHardMode where I have to create contents and post for 30 days straight. At first, I was quite hesitant. There were a lot of things that were going on in my head. Now that I have started it, it feels great to have taken the first step and it’s been very pleasing experience with a lot of support from my LinkedIn community. I shall talk about my Black Friday purchase today. hehe!
Puzzle 16: Reciprocals

I tried the solution in the live oracle environment here.
I got help from the advanced sql site as I was taking much longer time to think of the solution.
WITH temp As (
Select 1001 As PlayerA, 2002 AS PlayerB, 150 AS Score FROM Dual Union All
Select 3003 As PlayerA, 4004 AS PlayerB, 15 AS Score FROM Dual Union All
Select 4004 As PlayerA, 3003 AS PlayerB, 125 AS Score FROM Dual
)
SELECT a.PlayerA, a.PlayerB, SUM(Score)
FROM (
SELECT
(CASE WHEN PlayerA <= PlayerB THEN PlayerA ELSE PlayerB END) PlayerA,
(CASE WHEN PlayerA <= PlayerB THEN PlayerB ELSE PlayerA END) PlayerB,
Score
FROM temp
) a
GROUP BY PlayerA, PlayerB;

Leave a comment