Skip to content

Instantly share code, notes, and snippets.

@Ratstail91
Created June 10, 2019 07:05
Show Gist options
  • Save Ratstail91/324d08d956d74096e62e5da270bfdcb3 to your computer and use it in GitHub Desktop.
Save Ratstail91/324d08d956d74096e62e5da270bfdcb3 to your computer and use it in GitHub Desktop.
#new ladder expression
SELECT
username,
recruits,
soldiers,
gold,
(recruits + soldiers + scientists + spies) AS unitTotal,
(SELECT COUNT(*) FROM pastCombat WHERE (attackerId = accounts.id AND victor = 'attacker') OR (defenderId = accounts.id AND victor = 'defender')) AS successfulCombats,
(
(recruits + soldiers + scientists + spies) +
(SELECT COUNT(*) FROM pastCombat WHERE (attackerId = accounts.id AND victor = 'attacker') OR (defenderId = accounts.id AND victor = 'defender')) / 30 +
gold / 10
) as rankWeight
FROM
accounts JOIN profiles ON accounts.id = profiles.accountId
ORDER BY
rankWeight DESC
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment