This situation is a little specific so bear with me.

I have a (very) large table with many users (from a sync server). The users are stored by a hash identifier "username". Each user has many rows in the table where data is stored for them with a common username field.

I can get the total size used per user with the following (example) query: select username,round(sum(length(payload))/1024) from wbo where username = 's5i7goejhuxdfhulhpdqjubxgkskfdve'; This gives me the output I'm looking for for a single, known user.

What I'm looking for is a way to get a similar output, but then listing the users that have a total data (payload) size larger than a certain amount, so I can find the username IDs of all large data users, so they can be addressed. What query would I need for this?

1 Answer 1

select  username, round(sum(length(payload))/1024) AS metric
    from  wbo
    GROUP BY  username      -- to get one row per user
    ORDER BY  metric DESC   -- list biggest first
    LIMIT  50;              -- but show only 50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.