Fixed Stat's SQL queries