Skip to content
Advertisement

All records with Pivot table

I have table as below after pivoting,

I need like,

I need to remove all the null values and list like above table. My Query as below,

Thanks in advance.

Advertisement

Answer

Rather than using the modulus three, you should be using the remainder with a divisor of three. But I would avoid PIVOT here and just use a regular aggregation:

Here is a demo showing that the above query is working. Note that in the demo I don’t have an actual order_number column, but instead just used ORDER_ID. Coincidentally, this works fine, but would not work for more than 9 records, as text numbers don’t sort the same way as actual numbers.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement