Fix COUNT in sql statement