Well, you couldn't do this for the usernames (which should revert to the name of the user when they posted the post, anyway), but for the deletion of tables, after you do the select for users meeting the criteria, you need to run a loop to make a list of IDs. Once you have the list of IDs, you can feed them to each query in turn. So:
Code:
$idlist='0';
$result=$DB_site->query('SELECT userid FROM user WHERE (lastvisit<'.(time() - (60 * 60 * 24 * 487)).') AND (usergroupid IN (2, 3, 10, 11))');
while($userinfo=$DB_site->fetch_array()){
$idlist.=','.$userinfo['userid'];
}
$DB_site->query("DELETE FROM user WHERE userid IN (".$idlist.")");
$DB_site->query("DELETE FROM userfield WHERE userid IN (".$idlist.")");
$DB_site->query("DELETE FROM access WHERE userid IN (".$idlist.")");
$DB_site->query("DELETE FROM calendar_events WHERE userid IN (".$idlist.")");
$DB_site->query("DELETE FROM customavatar WHERE userid IN (".$idlist.")");
$DB_site->query("DELETE FROM moderator WHERE userid IN (".$idlist.")");
$DB_site->query("DELETE FROM privatemessage WHERE userid IN (".$idlist.")");
$DB_site->query("DELETE FROM subscribeforum WHERE userid IN (".$idlist.")");
$DB_site->query("DELETE FROM subscribethread WHERE userid IN (".$idlist.")");
$DB_site->query("DELETE FROM session WHERE userid IN (".$idlist.")");
To find userid's from previous cleanups, the query would be
[sql]SELECT usertextfield.userid FROM usertextfield LEFT JOIN user ON usertextfield.userid=user.userid WHERE ISNULL(user.username)[/sql]