Hello everyone,
i want to extract the records with Max("revision") from a table like this:
pn1 rev1 description
pn1 rev2 description
pn2 rev1 anotherdescription
pn1 rev3 description
pn2 rev2 anotherdescription
The first column is a part number, the second is its revision index (which is created every time the part number is modifyied).
That is quite easy in pure SQL:
SELECT
id,
pn,
revision,
description
FROM (SELECT
id,
pn,
revision,
MAX(revision)
OVER (
PARTITION BY pn ) max_rev,
description
FROM en_articles) maxart
WHERE revision = max_rev;
I cannot understand how to do the same with Django's ORM, i've tried every combination of Subquery/Window without getting anywhere.
Does anyone know how to do it?
Thanks in advance
Marco