How to get a subquery in FROM clause in Django ORM
问题 I'm trying to express the following (Postgres) SQL statement using the Django ORM: SELECT v.id, v.min_salary, v.max_salary, v.min_weekly_hours, v.max_weekly_hours p.min_start_date, p.max_end_date FROM vacancy v, ( SELECT id, vacancy_id, MIN(start_date) min_start_date, MAX(end_date) AS max_end_date FROM vacancypublication WHERE (active = True AND site_id = 1 AND start_date <= CURRENT_TIMESTAMP) GROUP BY id, vacancy_id ) p WHERE p.vacancy_id = v.id AND v.workflow_status = 'A' ORDER BY p.min