moved ranks select sql to ranks function