I wonder, if there is a way to sort data inside each row?
For example, I have table
val1, 3, 2, 1
val2, 2, 3, 1
val3, 3, 1, 2
val4, 1, 3, 2
val5, 1, 2, 3
and want to select it sorted, as
val1, 1, 2, 3
val2, 1, 2, 3
val3, 1, 2, 3
val4, 1, 2, 3
val5, 1, 2, 3
Best Answer
Well, see below. This is something I would definitely never write down in a real environment (I would question the original problem rather).
So far so good, just the sample data. Now do an UNPIVOT, then PARTITION BY val, ORDER BY the C values, then PIVOT back:
Limitations: