implement rank logic access from sql