working on SQL for filtered list