As you said: this query is weird :) Nevertheless it should be possible to do something like that.
You would need two functions and an additional table in your database: The table needs two columns, one for the user-name, one for the "last seen" timestamp. The first function is for saving the last-seen timestamp along with the correct username in the database (if possible, which means that the user either has to have a valid user cookie or an user-agent-string that identifies one of the prominent search engine bots). The second function queries the database for the names of all users that have been seen during the last x minutes and lists them somewhere on the page.
Should be easy if you know PHP and some of the WordPress internals.