+----+---------+-----------+---------------------+-----------+-----------+
| id | user_id | foo_id | created_at | active |type |
+----+---------+-----------+---------------------+-----------+-----------+
| 1 | 1 | 1 | 2011-05-10 13:12:35 | 1 | 2 |
| 7 | 5 | 2 | 2011-05-10 14:45:04 | 1 | 1 |
| 4 | 4 | 2 | 2011-05-10 13:24:45 | 1 | 2 |
| 8 | 6 | 2 | 2011-05-16 14:53:03 | 1 | 1 |
| 9 | 7 | 2 | 2011-05-16 14:55:11 | 1 | 0 |
+----+---------+-----------+---------------------+-----------+-----------+
这是一个在django中的UserMapper
模型。 我想编写一个查询这样的:如何在django查询集中解决这个特定查询
获取所有其foo_id = 2 and type=0
和user_id = 6;
说的所有结果USER_ID;
select * from table where user_id = 6 and (foo_id=2 and type=6) // Such sort of query
我怎样才能在Django查询集做..
你的SQL与你想要的描述不符。你的意思是'在哪里user_id = 6或(food_id = 2和type = 6)'? – 2011-05-16 10:36:36
我的意思是'其中user_id = 6'和'(food_id = 2和type = 6)' – 2011-05-16 10:42:24
但是这与'where user_id = 6 and food_id = 2 and type = 6'是一样的 - 即匹配所有三个标准,所以您的示例中没有任何行将匹配。你确定这就是你的意思吗? – 2011-05-16 10:45:25