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

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0d43b44c-996b-4dbd-86a2-d6312c8ac359%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to