lib.php: count ID value not all records
lib.php: fix bug in cancelled users GROUP BY and candidate status check