我正在尝试将查询转换为 eloquent 或找到一种在 Laravel Controller 中使用它的方法。
查询是:
select employee, workdate, sum(actualhours)
from ts_data group by employee, workdate;"
最佳答案
使用 Eloquent 模型:
$records = TsData::select(
'employee',
'workdate',
\DB::raw('sum(actualhours) as sumhours')
)
->groupBy('employee', 'workdate')
->get();
或使用数据库外观:
$records = \DB::table('ts_data')->select(
'employee',
'workdate',
\DB::raw('sum(actualhours) as sumhours')
)
->groupBy('employee', 'workdate')
->get();
关于Laravel eloquent中的Mysql按查询求和分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54789483/