You can use PIVOT to get the final result, but I would also suggest using a windowing function like row_number()
to get it. The windowing function will create a unique sequence for each color
in your ntile
value.
You should be able to use:
;with cte as
(
select ntile(4) over(order by color desc) n, color
from yourtable
)
select [1], [2], [3], [4]
from
(
select n, color,
row_number() over(partition by n order by n) seq
from cte
) d
pivot
(
max(color)
for n in ([1], [2], [3], [4])
) piv;