gpt4 book ai didi

doctrine-orm - Doctrine :不接受使用 equals 的 Select 语句

转载 作者:行者123 更新时间:2023-12-02 07:04:41 24 4
gpt4 key购买 nike

根据DDC-2204 issue其中指出

[Order by With Equals] is supported by including the condition in the SELECT clause, aliasing it, then using it. You might need to use "AS HIDDEN name" to prevent it from appearing in the result

以下 DQL 应该是可能的:

SELECT main.id = 1 AS test FROM Entity main ORDER BY test

但是,当我尝试这个(使用 2.4)时,我得到了

Error: Expected Doctrine\ORM\Query\Lexer::T_FROM, got '='

开发人员建议的将条件放入 SELECT 的方法似乎不起作用。这是一个错误和/或是否有另一种选择和/或按条件排序的方法。

最佳答案

可以使用case语句:

SELECT (CASE WHEN main.id = 1 THEN 1 ELSE 0 END) AS test FROM Entity main ORDER BY test

关于doctrine-orm - Doctrine :不接受使用 equals 的 Select 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25761989/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com