Fix stats SQL and markup