3
I have a history table on DB2
and would like to carry out a PLACA
however despite this I would have to return the last 5 records of each PLACA
.
Ex.:
|ID |PLACA | DATA | VALOR | |12 |ABC | 2014-08-28 | 4.50 | |11 |DFG | 2014-08-28 | 3.50 | |10 |ABC | 2014-08-27 | 2.50 | |9 |DFG | 2014-08-27 | 4.50 | |8 |DFG | 2014-08-26 | 3.50 | |7 |ABC | 2014-08-26 | 2.50 | |6 |DFG | 2014-08-25 | 4.50 | |5 |DFG | 2014-08-24 | 3.50 | |4 |ABC | 2014-08-24 | 2.50 | |3 |DFG | 2014-08-23 | 4.50 | |2 |ABC | 2014-08-23 | 4.50 | |1 |ABC | 2014-08-22 | 4.50 |
Should return:
The records of ID
12, 10, 7, 4 and 2 of PLACA
ABC
and
The records of ID
11, 9, 8, 6 and 5 of PLACA
DFG
Expected return:
|ID |PLACA | DATA | VALOR | |12 |ABC | 2014-08-28 | 4.50 | |10 |ABC | 2014-08-27 | 2.50 | |7 |ABC | 2014-08-26 | 2.50 | |4 |ABC | 2014-08-24 | 2.50 | |2 |ABC | 2014-08-23 | 4.50 | |11 |DFG | 2014-08-28 | 3.50 | |9 |DFG | 2014-08-27 | 4.50 | |8 |DFG | 2014-08-26 | 3.50 | |6 |DFG | 2014-08-25 | 4.50 | |5 |DFG | 2014-08-24 | 3.50 |
What return format do you expect, Cristiano? Serialized ids (e.g. | ABC | 12, 10, 7, 4, 2 |)? Individual recordsets? Add to your question an example of the desired return.
– OnoSendai
Which database?
– gmsantos