Summary
SQL Query for Data model
Content
Hello,
I'm working on an RTF template on which I want to display certain information of a table called "shipment_stop_debrief". In this table figures serveral “S_SHIP_UNIT_GID’s" with different numbers. I want the quantity of "ITEM_PACKAGE_COUNT" and "TRANSPORT_HANDLING_UNIT_COUNT" for the last "S_SHIP_UNIT_GID" of a certain type.
When I say last of a certain type, I mean that a “S_SHIP_UNIT_GID" can be updated and in some cases and it will create another “S_SHIP_UNIT_GID" with the same reference number, but I only need the most recent (lastly updated) “S_SHIP_UNIT_GID" of a same reference number.
Example in the screen below, which shows two same ship_unit_gid’s with different quantities, I want to select the one that is most recent which corresponds to the one with a quantity of 13 :
The SQL that corresponds to it is this one:

SELECT *
FROM
(SELECT *
FROM shipment_stop_debrief
WHERE SHIPMENT_GID = 'PEI.H171123883'
ORDER BY INSERT_DATE DESC)
So ship_unit_gid’s are ordered by date and I would like to select PEI.205165, PEI.205166, PEI.205164 (with the quantity of 13).
Do you guys have any idea ?
Thanks,
Antoine