Need some help to solve below. I have a table:
expected result:
below logic should be applied by SQL. IF "Indicator" = T1, then need to find lowest "KEY-XXX-1", Column "IN/OUT" should be converted into separate Columns and insert the dates. If "Indicator" = T2, then need to find top "KEY-X-?" by last digits after '-', convert "IN/OUT" into separate Columns and take corresponding dates.
any help would be greatly appreciated!



Query:
Output: