Fix popularity sql