Skip to content

Instantly share code, notes, and snippets.

@jammaloo
Created January 16, 2020 22:27
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 jammaloo/c13aa2cfaf103cc16f856ff948522bfc to your computer and use it in GitHub Desktop.
Save jammaloo/c13aa2cfaf103cc16f856ff948522bfc to your computer and use it in GitHub Desktop.
# Simple version
SELECT
username,
max(connected),
max(disconnected)
FROM radacct
GROUP BY username
# Using subqueries
SELECT
lc.username,
lc.last_connect,
dc.last_disconnect
FROM (
SELECT
username,
max(connected) AS last_connect
FROM radacct
GROUP BY username) AS lc LEFT JOIN (SELECT
username,
max(disconnected) AS last_disconnect
FROM radacct
GROUP BY username) AS dc ON dc.username = lc.username
WHERE lc.last_connect <= dc.last_disconnect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment