I need to value the inventory of the company in which I work and for this I will get the last value of the items. I was using MAX
, but I realized that if I did this, it would return me the highest price and not the last one registered in the table. So I changed the MAX
to the date column, except that it brings me several rows of results, and I only need the last but still with the code and value field to then play in a worksheet.
Code:
SELECT irec.pro_in_codigo Codigo,
irec.rci_re_vlunitario Valor_unitario,
max(irec.rcb_dt_documento) Data
FROM mgadm.est_itensreceb irec
WHERE irec.pro_in_codigo = 701
GROUP BY irec.pro_in_codigo, irec.rci_re_vlunitario