Skip to content

Instantly share code, notes, and snippets.

@aikar
Created April 17, 2018 16:18
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 aikar/9c8295b9e97c43c7e7e49a2d42943bb1 to your computer and use it in GitHub Desktop.
Save aikar/9c8295b9e97c43c7e7e49a2d42943bb1 to your computer and use it in GitHub Desktop.
SELECT
u.name,
u.first_login,
(u.last_login - u.first_login) AS age,
($now - GREATEST(IF(u.lastvote > $voteWindow, u.lastvote, 0), u.last_activity)) as since_last,
r.address,
'derelict' as reason
FROM
residence AS r
LEFT JOIN
user AS u ON r.owner_user_id = u.user_id
WHERE
r.owner_user_id IS NOT NULL
AND
u.user_group_id < 2
AND
u.derelict_protection = 0
AND
(
(u.first_login < $oneYearAgo && GREATEST(IF(u.lastvote > $voteWindow, u.lastvote, 0), u.last_activity) < $oneMonthAgo)
||
(u.first_login > $oneMonthAgo && GREATEST(IF(u.lastvote > $voteWindow, u.lastvote, 0), u.last_activity) < $tenDaysAgo)
)
AND
u.last_supported < $oneMonthAgo
AND
server_id = $serverId
ORDER BY age ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment