gpt4 book ai didi

php - Laravel-多个查询

转载 作者:行者123 更新时间:2023-12-03 18:32:59 25 4
gpt4 key购买 nike

我试图在sqlite数据库上使用多个where查询,然后仅在两个日期ssDate和seDate之间选择查询。由于某种原因,当我知道两个日期之间有一个条目时,我什么也没有退回。

        if($status == "newOngoingClosed"){
//dd($status, $ssDate, $seDate);
$selStatus = Account::where('cActive', '=', 'New')
->orWhere('cActive', '=', 'Ongoing')
->orWhere('cActive', '=', 'Closed')
->whereBetween ('refDate', [$ssDate, $seDate])
->get();
dd($selStatus);
return view('reports_active')->withDetails($selStatus)->withQuery($status);
}


任何帮助将不胜感激。

最佳答案

您的查询当前是:

select * 
from `accounts`
where `cActive` = ? or `cActive` = ? or `cActive` = ? and `refDate` between ? and ?


请注意,最后一个条件是AND,这意味着它将选择在这些日期之间是新的,正在进行的或已关闭的事物

你需要:

Account::where([
['cActive', '=', 'New','or'] ,
[ 'cActive', '=', 'Ongoing','or' ],
['cActive', '=', 'Closed','or']
])->whereBetween ('refDate', [Carbon::now(), Carbon::now()])->get() //Note the carbons are just date placeholders , you can use your own


这将执行:

select * from `accounts` where (`cActive` = ? or `cActive` = ? or `cActive` = ?) and `refDate` between ? and ?

关于php - Laravel-多个查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50252976/

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