refactor FIRST|LAST BY to FIRST_LAST VALUE