I could not find a suitable answer so I am writing it here. I have a table with following fields.
ID Amount DocNum DocStatus DueDate
AA 2400 00005 1 10-Jun-2019
AA 1400 00006 4 21-Sep-2019
AA 9000 00028 1 22-Aug-2020
AA 5000 00201 2 31-Aug-2020
AA 6400 00410 1 22-Jan-2021
AA 2000 00511 1 01-Mar-2021
BB 1500 01390 1 01-Jan-2021
I would want to display a top 3 latest documents with Status 1
ID Document1 Amount1 Document2 Amount2 Document3 Amount3
AA 00511 2000 00410 6400 00028 9000
BB 01390 1500 XX XX XX XX
I thought I could use Pivot or Decode but unable to determine other conditions. Any help is appreciated.