8

これが私のHQLです:

Query query = createQueryOnCurrentSession("DELETE Email e " +
                "where " +
                "(status = :sent and creationTime <= :creation)" +
                "or " +
                "(status = :error and maxEttempts >= :maxEttempts)");

生成されたSQLは次のとおりです。

delete from `email` where `status`=? and `creation_time`<=? or `status`=? and `attempts`>=?

質問:角かっこがSQLにないのはなぜですか?私はそれが次のようになることを期待します:

delete from `email` where (`status`=? and `creation_time`<=?) or (`status`=? and `attempts`>=?)

代わりに、2つのリクエストで削除する可能性がありますか?

delete from `email` where `status`=? and `creation_time`<=?
delete from `email` where `status`=? and `attempts`>=?
4

2 に答える 2

11

実は特徴です。

andは よりも優先されるためor、休止状態はそれを認識し、ブラケットを削除します。

そこにそれらのブラケットは必要ありません。

于 2012-12-17T07:58:13.947 に答える
2

論理演算子ANDは、論理演算子ORよりも優先順位が高くなります

演算子の優先順位については、リンクをたどってください

http://dev.mysql.com/doc/refman/5.0/en/operator-precedence.html
http://msdn.microsoft.com/en-us/library/ms190276.aspx

http://docs.oracle.com/html/A85397_01/operator.htm#997691
于 2012-12-17T08:20:19.870 に答える