Can somebody help me with SQL using pivot?
For example I have a list shown below with 1 column:
and I want the result to become this:
I tried pivot but I only got 1 row.. I just need multiple rows.
Can somebody help me with SQL using pivot?
For example I have a list shown below with 1 column:
and I want the result to become this:
I tried pivot but I only got 1 row.. I just need multiple rows.
You can use window functions. In your case, you have a sequence with no gaps, so you can just use modulo arithmetic:
select max(case when units % 10 = 1 then units end),
max(case when units % 10 = 2 then units end),
. . .
max(case when units % 10 = 0 then units end)
from t
group by ceiling(units / 10.0);