【发布时间】:2012-01-23 06:52:03
【问题描述】:
如何在 django 的查询集中有一个子查询?例如,如果我有:
select name, age from person, employee where person.id = employee.id and
employee.id in (select id from employee where employee.company = 'Private')
这就是我所做的。
Person.objects.value('name', 'age')
Employee.objects.filter(company='Private')
但它不起作用,因为它返回两个输出...
【问题讨论】:
-
你的例子不是很好。您不需要子查询:
select name, age from person, employee where person.id = employee.id and employee.company = 'Private'