• There are few ways of doing this, my guess is that you are not close to any of them but in order to help you find an acceptable solution, you must elaborate on Alan's request and post the DDL (create table), sample data as an insert statement and finally the expected result set. Take care in posting the full problem as piecemeal'ing it doesn't do anything but waste everyone's time.

    😎