我有這條線在我的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