我是拉拉维尔的新手,我想用拉拉维尔格式编写下面的SQL。
SELECT user, SUM(total_net_amount) AS total
FROM primary_invoices
GROUP BY user_id
提前致谢
这是我正在寻找的确切答案。我希望这会帮助其他人。
$report_dates = DB::table('primary_invoices')
->select('user','datee', DB::raw('SUM(total_net_amount) as total'))
->where(function ($query) use($date_value,$enddate_value) {
$query->whereBetween('datee', [$date_value, $enddate_value]);
})
->where('user',$search_value)
->groupBy('datee')
->orderBy('datee','asc')
->get();
PrimaryInvoice::selectRaw('SUM(total_net_amount) as total')
->groupBy('user_id')
->get()
如果primary_invoices与 users 表有关系,则可以使用如下所示的内容:
PrimaryInvoice::selectRaw('SUM(total_net_amount) as total, user_id')
->with('user')
->groupBy('user_id')
->get()