gpt4 book ai didi

symfony - Doctrine SQL 查询 Order By ASC NULL Last

转载 作者:行者123 更新时间:2023-12-02 03:19:48 26 4
gpt4 key购买 nike

我使用 Doctrine 2.4。我尝试按优先级升序对营销事件列表进行排序,优先级为 NULL,最后优先级为 0。

SELECT * FROM campaign ORDER BY priority IS NULL, priority = 0, priority ASC

你知道我该怎么做吗?

$query->addOrderBy('c.priority', 'ASC');

最佳答案

我找到了解决方案,我做到了:

$query->addSelect('CASE WHEN c.priority IS NULL THEN 1 ELSE 0 END as HIDDEN priority_is_null');
$query->addSelect('CASE WHEN c.priority = 0 THEN 1 ELSE 0 END as HIDDEN priority_is_zero');
$query->addOrderBy('priority_is_null', 'ASC');
$query->addOrderBy('priority_is_zero', 'ASC');
$query->addOrderBy('c.priority', 'ASC');

关于symfony - Doctrine SQL 查询 Order By ASC NULL Last,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55146795/

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