Tuesday, November 29, 2016

rewrite PostgreSQL query to Django ORM

Hello, how to rewrite this PostgreSQL query to Django ORM with no raw SQL ?


select * from finance_fund order by((select price from finance_nav where date='2016-11-08' and fund_id=finance_fund.id)/(select price from finance_nav where date='2016-11-07' and fund_id=finance_fund.id)) LIMIT 30;

So basically i need to order by division result of two simple queries of backward relations of Foreign key

Thanks in advance !

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/9fbf9c99-c914-437b-aae2-a366a0f8eaec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment