gpt4 book ai didi

php - Laravel orderBy 与列值

转载 作者:行者123 更新时间:2023-12-01 01:13:29 24 4
gpt4 key购买 nike

这是我目前拥有的代码:

$programmefundings = Programmefunding::where('status', '!=', 'draft')->orderByRaw("FIELD(status , 'open', 'announced', 'delayed', 'closed') ASC")->orderBy('date_start', 'desc')->get();

因此,它获取了我所有的计划资金,除了状态为“草稿”的资金,并将其从“开放”重新排序为“已关闭”> 并按'date_start'排列它们。

我需要按照 'asc' 顺序对另一列'announcement_date' 状态为“已宣布”的计划资金重新排序,而不影响'open' 更改为当前具有的“已关闭”结构,并且不会影响任何其他不具有状态值“已宣布”的计划结果。

这可能吗?有人知道如何做到这一点吗?

谢谢!

最佳答案

您应该能够使用 IF 语句来执行此操作。

$programmefundings = Programmefunding::where('status', '!=', 'draft')
->orderByRaw("FIELD(status , 'open', 'announced', 'delayed', 'closed') ASC")
->orderByRaw("IF(status = 'announced', accouncement_date, date_start) DESC")
->get();

关于php - Laravel orderBy 与列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45624879/

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