Can you do this with the Django ORM?

25 views
Skip to first unread message

rossm6

unread,
Mar 21, 2020, 11:53:41 AM3/21/20
to django...@googlegroups.com
Can the django ORM do something like this?

SELECT * FROM "products_maxbid" as m
JOIN "products_auction" as a on m.auction_id = a.uuid
WHERE m.uuid in (
    SELECT m.uuid FROM "products_maxbid" as m
    INNER JOIN (
        SELECT auction_id, Max(value) as value FROM "products_maxbid"
        WHERE user_id = '2'
        GROUP BY auction_id
) n
on m.auction_id = n.auction_id and m.value = n.value and m.user_id = '2'
)
ORDER BY a.square_id
SO question - https://stackoverflow.com/questions/60789513/django-query-for-max-value-for-column-which-includes-foreign-key-table-also-in-r

johnf

unread,
Mar 21, 2020, 12:45:34 PM3/21/20
to django...@googlegroups.com
google "django send raw sql"

Johnf
--
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 django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJXS7_MePOU_LYhVWLKsG0gz4XyVdDS8w4LhpFyYCQpQVUGkOw%40mail.gmail.com.

Reply all
Reply to author
Forward
0 new messages