0

Can somebody help me with SQL using pivot?

For example I have a list shown below with 1 column:

enter image description here

and I want the result to become this:

enter image description here

I tried pivot but I only got 1 row.. I just need multiple rows.

1
  • why would you want such output , just out of curiosity what's the real life use case ? Commented May 28, 2021 at 1:56

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.