【发布时间】:2021-03-16 02:51:02
【问题描述】:
我的目标是将以下 SQL 查询转换为 Laravel 查询构建器语法,
$qstA = "
select sum(tmpbutbldata.Personnel_Hours_Spent) as PHS from tmpbutbldata
left join tbl_testlocation_links on tmpbutbldata.Test_Request_Number= tbl_testlocation_links.Test_Request_number
where
tmpbutbldata.Date_Test_Completed between '".$dateBack."' and '".$dateCurr."'
and tbl_testlocation_links.".$Location."='1'
and tmpbutbldata.type = '1'
and tmpbutbldata.cancelled = '0'
or
tmpbutbldata.Date_Test_Completed between '".$dateBack."' and '".$dateCurr."'
and tbl_testlocation_links.".$Location."='1'
and tmpbutbldata.type = '2'
and tmpbutbldata.cancelled = '0'"
;
我尝试过的:
DB::table("tbldata")
->select(DB::raw('*'))
->leftJoin('tbl_testlocation_links', 'tbldata.Test_Request_Number', '=', 'tbl_testlocation_links.Test_Request_number')
->where(['Date_Test_Completed', '<', $dateBack],
['Date_Test_Completed', '>', $dateCurr],
['tbl_testlocation_links'.$location->TestLocation, '=', 1],
['type', '=', 1],
['cancelled', '=', 0])
->orWhere(['Date_Test_Completed', '<', $dateBack],
['Date_Test_Completed', '>', $dateCurr],
['tbl_testlocation_links'.$location->TestLocation, '=', 1],
['type', '=', 2],
['cancelled', '=', 0])
->get();
但我得到以下错误 ErrorException 数组到字符串的转换
【问题讨论】:
-
你在哪一行得到错误?
-
在 ->get() 行
-
好的,谢谢你的帮助!
标签: php mysql laravel laravel-query-builder