I need to do a filter on the last purchase price for my list of products, but I need only the first row of each product (it is already on the correct order).
Example:
PRODUCT CODE PRICE PURCH.DATE
-----------------------------------------------------
PO.MC.PER.001.N.PORTVIDEOCARD 0,3 20140521
PO.MC.PER.001.N.PORTVIDEOCARD 0,3 20140203
PO.MC.PER.001.N.PORTVIDEOCARD 0,3 20131115
PO.MC.PER.001.N.PORTVIDEOCARD 0,6 20130625
PO.MC.PER.001.N.PORTVIDEOCARD 0,5 20121122
SV.AI.SEI.006.N.CONFIEQUIPARE 800 20121211
SV.AI.SEI.006.N.CONFIEQUIPARE 3675 20121211
SV.AI.SEI.006.N.CONFIEQUIPARE 2000 20121114
SV.AI.SEI.006.N.CONFIEQUIPARE 2000 20120904
SV.AI.SFT.001.N.SOFTGERENCAME 2184 20121210
TI.AI.COP.001.N.NOTEBOOKPCXXX 3020,28 20110902
TI.AI.COP.002.N.COMPUTDESKTOP 2466,47 20140123
TI.AI.COP.002.N.COMPUTDESKTOP 2572 20131107
TI.AI.COP.002.N.COMPUTDESKTOP 2320 20131001
TI.AI.COP.002.N.COMPUTHP300GB 1517,5 20111130
TI.AI.COP.002.N.HPSMARTARRAYP 548,7 20111130
TI.AI.COP.002.N.UTRIUM920SAS 6050,6 20111130
TI.AI.COP.006.N.NOTEBOOKHPXXX 3020,28 20111117
TI.AI.COP.008.N.COMPUTINTELXE 1715 20111130
TI.AI.COP.009.N.COMPHP460WCSH 916,6 20111130
TI.AI.COP.011.N.MONITCOMPUTAD 25 20130613
TI.AI.COP.011.N.MONITCOMPUTAD 478 20130521
then I expect to have the following result:
PRODUCT CODE PRICE PURCH.DATE
-----------------------------------------------------
PO.MC.PER.001.N.PORTVIDEOCARD 0,3 20140521
SV.AI.SEI.006.N.CONFIEQUIPARE 800 20121211
SV.AI.SFT.001.N.SOFTGERENCAME 2184 20121210
TI.AI.COP.001.N.NOTEBOOKPCXXX 3020,28 20110902
TI.AI.COP.002.N.COMPUTDESKTOP 2466,47 20140123
TI.AI.COP.002.N.COMPUTHP300GB 1517,5 20111130
TI.AI.COP.002.N.HPSMARTARRAYP 548,7 20111130
TI.AI.COP.002.N.UTRIUM920SAS 6050,6 20111130
TI.AI.COP.006.N.NOTEBOOKHPXXX 3020,28 20111117
TI.AI.COP.008.N.COMPUTINTELXE 1715 20111130
TI.AI.COP.009.N.COMPHP460WCSH 916,6 20111130
TI.AI.COP.011.N.MONITCOMPUTAD 25 20130613
So, the final query will only show me the last price for EACH product, ONCE
I can't use distinct
because they are already obviously distinct (although the product repeats, the price and/or purchase date don't)
I'm using SQL Server 2008 R2