Skip to content

Instantly share code, notes, and snippets.

@pradeepwebonise
Created July 29, 2015 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pradeepwebonise/b43eae784ba6b30cfbed to your computer and use it in GitHub Desktop.
Save pradeepwebonise/b43eae784ba6b30cfbed to your computer and use it in GitHub Desktop.
Leaderboard Data query with indexing
/* Leaderboard Data query */
EXPLAIN PLAN FOR
SELECT userId, firstName, lastName, userName, email, entryId, totalPayouts FROM (
SELECT rownum as rn, a.* FROM (
SELECT u.user_id userId, u.first_name firstName, u.last_name lastName,
u.user_name userName, tep.entry_id entryId,
NVL( SUM(p.payouts), 0 ) totalPayouts ,u.email email
FROM USERS u, TOURNAMENT_USERS_ENTRY tue, TOURNAMENT_ENTRY_PICK tep
LEFT JOIN PICK_PAYOUT p ON tep.pick_id = p.pick_id
WHERE u.user_id = tue.user_id AND
tue.tournament_id = 110 AND
tep.entry_id = tue.entry_id
GROUP BY u.user_id, u.first_name, u.last_name, u.user_name, tep.entry_id , u.email
ORDER BY totalPayouts DESC, firstName, lastName
) a
) WHERE rownum <= 10 AND rn > (1 - 1) * 10;
==================================== OUTPUT ==============================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment