We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I ended up getting rid of the last CTE I had made and instead putting it all in the final select statement similar to yours, but at first I had the following and for some rows I got the wrong output (lower than expected), althought most were correct. Can somebody help me understanad why?
Thank you
WITHAAS(SELECTchallenge_id,SUM(total_submissions)AStotal_challenge_submissions,SUM(total_accepted_submissions)AStotal_challenge_accepted_submissionsFROMSubmission_StatsGROUPBYchallenge_id),BAS(SELECTchallenge_id,SUM(total_views)AStotal_challenge_views,SUM(total_unique_views)AStotal_challenge_unique_viewsFROMView_StatsGROUPBYchallenge_id),/*In final solution, this CTE was deleted and logic moved down to final SELECT statement*/CAS(SELECThacker.hacker_idAShacker_id,hacker.nameASname,college.contest_idAScontest_id,college.college_idAScollege_id,challenge.challenge_idASchallenge_idFROMContestsAShackerJOINCollegescollegeONhacker.contest_id=college.contest_idJOINChallengesASchallengeONcollege.college_id=challenge.college_id)SELECTC.contest_id,C.hacker_id,C.name,SUM(A.total_challenge_submissions),SUM(A.total_challenge_accepted_submissions),SUM(B.total_challenge_views),SUM(B.total_challenge_unique_views)FROMCLEFTJOINBONC.challenge_id=B.challenge_idLEFTJOINAONA.challenge_id=B.challenge_idGROUPBYC.contest_id,C.hacker_id,C.nameHAVINGSUM(A.total_challenge_submissions)+SUM(A.total_challenge_accepted_submissions)+SUM(B.total_challenge_views)+SUM(B.total_challenge_unique_views)<>0ORDERBYC.contest_id;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Interviews
You are viewing a single comment's thread. Return to all comments →
Hello,
I ended up getting rid of the last CTE I had made and instead putting it all in the final select statement similar to yours, but at first I had the following and for some rows I got the wrong output (lower than expected), althought most were correct. Can somebody help me understanad why?
Thank you