我想總結主題表中的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