Sql cleanup

I don't see how this complicated sql statement ended up in here in the first place. But I'm quite certain, that my version will not only work just as well, but actually perform a little better.

Would have used "NOT (last_activity>0)" in the where clause, but testing on sqlfiddle.com suggested that I need to do it the way it is now in the pull request.