Hi Experts,
I am trying to do dynamic pivot query. I know how to transpose a query to pivot. But I am just wondering can I do pivot.
For example.
A classic pivot:
>>select * from sec_q;
the column names respectively are:
invoiceid invoice_amount invoice_row_num
01032925 196,28 1
01048083 152,57 1
01048083 98,87 2
01053119 188,5 1
01070391 358,84 1
01078898 165,78 1
01081126 157,57 1
01085899 87,19 1
01085899 1,31 2
01085899 164,82 3
However, I don't know the max invoice_row_num value because it can decrease dynamicly
I want the following output
accountnum invoice_num_1 invoice_num_2 invoice_num_3...... invoice_num_max
01085899 87,19 1,31 164,82 0
01081126 157,57 0 0 0
As far as I know the following cannot meet my expectations
SELECT * FROM sec_q
pivot
(max(invoiceamount) for (row_num) in ('1', '2', '3', '4', '5' *BECAUSE THIS VALUE CHANGE DYNAMICLY * ));
So, suppose that my table like below
sec_q
(
accountnumnumber,
invoice_amount number,
invoice_row_num number
)
each accountnum does not dublicate, and all invoice_amoun tranpose and the column headers should be invoice_row value
Does it possible?
Thanks in advance