Session Statistics by User
select a.username, count(*) as total_sessions, sum(s.bytes_sent) as total_bytes_sent, sum(s.bytes_received) as total_bytes_received from ores.sessions s join ores.accounts a on a.id = s.account_id and a.valid_to = '9999-12-31 23:59:59'::timestamptz group by a.username order by total_sessions desc;