An alternative fix I found for the mysql 'usergroup' table related errors is to adding 'AS usergroup' on the second LEFT JOIN in the initial $referrals query resolves the problem and allows the group markup to work.
Code:
$referrals = $db->query_read("SELECT COUNT(*) AS totalref, user.username, user.userid, user.usergroupid, usergroup.usergroupid, usergroup.opentag, usergroup.closetag
FROM " . TABLE_PREFIX . "user AS users
LEFT JOIN " . TABLE_PREFIX . "user AS user ON (users.referrerid = user.userid)
LEFT JOIN " . TABLE_PREFIX . "usergroup AS usergroup ON (usergroup.usergroupid = user.usergroupid)
WHERE users.referrerid != 0
GROUP BY users.referrerid
ORDER BY totalref
DESC LIMIT 0,$num");