I have a table called balance
which I wish to pivot, however it is quite difficult since the column names would be labelled 1,2,3 and balances would be sorted by descending order per customer.
This is screenshot of current table:
And the pivot table:
I reviewed other videos and post but I didn't find a solution to match my current situation what I want to achieve. So the final results would be the customer would be sorted by asc and balances would be sorted by desc. So for customer 3 the highest balance of 500 would be placed in column 1, 300 in column 2 and in 250 in column 3.
Script to create sample data:
select Customer, Balance
into #a
from (
values
(1, 250),
(2, 500),
(1, 205),
(2, 600),
(2, 700),
(3, 300),
(3, 500),
(3, 250)
) v (Customer, Balance)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…