0

我正在尝试执行与此 SQL 查询等效的操作:

"SELECT * FROM something WHERE ((something >= something AND something <= something) AND(something >= something AND something <= something))"

我无法完全弄清楚。我试过以下没有成功..

.filter(( Q(something__gte=something) & Q(something__lte=something)) & ( Q(something__gte=something) & Q(something__lte=something)))

.filter( Q(something__gte=something,something__lte=something) & Q(something__gte=something,something__lte=something))

两者都返回以下内容..并完全忽略了我的括号...

WHERE (`something`.`something` >= something  AND `something`.`something` <= -something  AND `something`.`something` >= something  AND `something`.`something` <= something )
4

1 回答 1

3

逻辑运算符 AND 是关联的。a & b & c == (a & b) & c == a & (b & c)。不需要括号

于 2011-07-26T15:28:59.930 回答