Skip to Content
0
Mar 24 at 07:25 PM

last sale query for an item

73 Views

Good afternoon, I want to know the last sale of each article, I have a query to the inv1 table that I can't find because, for example, an article made 10 sales yesterday and today it had 7 sales, my query brings me 7 Today's sales and I just want the last record of those sales.

my version of sap business one does not have the "DocTime" field

SELECT T0."ItemCode", T0."DocDate", T0."BaseEntry" AS UltimaVenta, T0."Quantity"
FROM INV1 T0
INNER JOIN (
SELECT T1."ItemCode", MAX(T1."DocDate") AS "UltimaVenta"
FROM INV1 T1
GROUP BY T1."ItemCode"
) AS T2
ON T0."ItemCode" = T2."ItemCode" AND T0."DocDate" = T2."UltimaVenta"
ORDER BY T0."DocEntry" DESC