我有这条线在我的SQL查询:SQL查询的WHERE子句
WHERE client = $id
AND (isinvoiced = 0) OR (isinvoiced = 1 and isrecurring = 1)
其得到更多的结果,比我期待的。不过,如果我这样写:
WHERE client = $id
AND (isinvoiced = 0) OR (isinvoiced = 1 and isrecurring = 1 and client = $id)
然后它得到我想要的结果,但这是写这个最好的方法吗?我只是不想再遇到这个代码的更多问题。
Google for [Distributivity rewrite rules](http://en.wikipedia.org/wiki/Distributivity)。 – onedaywhen 2012-04-23 15:32:37
你确定你明白'a AND b OR c'和'a AND(b OR c)'的区别吗?你的例子更清楚地写成'(a AND b)或c',而不是你真正想要的。 – MatBailie 2012-04-23 15:38:08