dtmwnqng38644 2019-05-10 08:44
浏览 37
已采纳

doctrine2 querybuilder之间没有

I'd like to make a MySQL query with doctrine2 QueryBuilder (Symfony 3.4 app) with a NOT BETWEEN statment.

The doctrine provide a ->expr()->between(..) but not ->expr()->notBetween(..)

Is there a way to negate the between with the query builder.

I don't want to use a native or a DQL query if possible.

Note: I think a possible solution is to use ->expr()->lt(..) and/or ->expr()->gt(..) but I want to know if notBetween is possible.

Thanks

Expected:

A NOT BETWEEN SQL statement with Doctrine2 QueryBuilder

  • 写回答

1条回答 默认 最新

  • doujiu7704 2019-05-10 09:41
    关注

    After some attempts, I found a suitable solution for me:

    The QueryBuilder provide a ->expr()->not(...), so in this case this is possible:

    $qb->exp()->not($qb->between('field', 'from', 'to')

    SQL result: NOT (BETWEEN field from AND TO)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?