我用的是Laravel5.4。我的书面质询与拉威尔雄辩。当我手动将查询写入mysql服务器时,它工作正常,但当我使用laravelelelounk编写相同的查询代码时,它就不工作了。
请帮忙。。。
拉斐尔码
$dateS = new Carbon($req->fromDate);
$dateE = new Carbon($req->toDate);
$tasks = DB::table('taskday')->selectRaw("taskday.dayID, taskday.task_date, taskday.fk_userID, userdetails.fullname, count(assignedtask.fk_dayID) as total")
->join("assignedtask","assignedtask.fk_dayID","taskday.dayID")
->join("userdetails","userdetails.userID","taskday.fk_userID")
->whereBetween("taskday.task_date", [$dateS->format('Y-m-d')." 00:00:00", $dateE->format('Y-m-d')." 23:59:59"]);
if($req->staffname > 0){
$tasks = $tasks->where('taskday.fk_userID',$req->staffname);
}
$tasks = $tasks->groupBy("assignedtask.fk_dayID")->get();
return $tasks;
我的sql查询
select `taskday`.`dayID`, `taskday`.`task_date`, `taskday`.`fk_userID`, `userdetails`.`fullname`, count(`assignedtask`.`fk_dayID`) as total
from `taskday` inner join `assignedtask` on `assignedtask`.`fk_dayID` = `taskday`.`dayID`
inner join `userdetails` on `userdetails`.`userID` = `taskday`.`fk_userID`
where `taskday`.`task_date` between '2018-11-01 00:00:00' and '2018-12-19 23:59:59'
group by `assignedtask`.`fk_dayID`
直接在mysql上进行fire查询后,它会给出正确的结果
dayID task_date fk_userID fullname total
-------- ---------- ---------- ---------- -------------
DAY021 2018-12-02 USR300920 Manish 2
DAY022 2018-12-03 USR300924 Rovio 3
拉威尔给出了错误
(2/2) QueryException
SQLSTATE[42000]: Syntax error or access violation: 1055 'medical.taskday.dayID'
isn't in GROUP BY
(SQL: select taskday.dayID, taskday.task_date, taskday.fk_userID, userdetails.fullname, count(assignedtask.fk_dayID) as total
from `taskday` inner join `assignedtask` on `assignedtask`.`fk_dayID` = `taskday`.`dayID`
inner join `userdetails` on `userdetails`.`userID` = `taskday`.`fk_userID`
where `taskday`.`task_date`
between 2018-11-01 00:00:00 and 2018-12-19 23:59:59
group by `assignedtask`.`fk_dayID`)
请帮忙
1条答案
按热度按时间irtuqstp1#
如果我理解你的问题,试试这个。
控制器
请检查您的时间戳格式的数据库,它必须与此相同或尝试使用unixtime格式查询“wherebetween”更准确的计算。
看法
为了编码的和平:)