我想总结主题表中的numofunit
和total price
。我已经做了我被告知在谷歌上做的事情,但是我仍然遇到了一些模糊的错误。我想知道我是否这样做是正确的,因为我在laravel中查询db还是个新手。老实说,我不太清楚的语法laravel总结函数
这是查询的一个片段:
$results = DB::table('subjects')
->join('subjectblocking', 'subjects.subjectcode', '=', 'subjectblocking.subjectcode')
->join('grades', 'subjectblocking.blockcode', '=', 'grades.blockcode')
->select('subjects.numofunit as total_units, subjects.price as total_tuition')
->sum('subjects.numofunit','subjects.price')
->orWhere(function($query)
{
$query->where('grades.studentid', '=', '2013-F0218')
->where('sem', '=', '1')
->where('sy', '=', '2013-2014');
})
->get();
这是我遇到的错误:
调用一个成员函数orWhere()非对象 在线72上:其为 - > orWhere(函数($查询)
相信我声明$query
,所以我不知道为什么我仍然收到错误
糟糕,你说得对。我会相应地改变我的评论。 – 2014-12-05 21:59:05
谢谢@ColinSchoen @JoelHinz!我现在得到语法,但是在我移动了* - > sum('subjects.numofunit','subjects.price')之后; *它导致了我的返回视图的错误。 – 2014-12-06 07:49:13