sql - 在 LARAVEL 中使用 group by 子句检索列的总和
问题描述
我是 laravel 的新手,我想以LARAVEL格式编写以下 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();
推荐阅读
- vb.net - 更改表单语言时如何更改表单标题?
- azure - 无法使用 Azure Graph API 获取 B2B 用户的详细信息
- ffmpeg - 使用命令行为 P 帧提取特定于帧的所有 H.264 NALU
- opencv - 如何检测此图像的边缘?
- javascript - 从渲染器到主的电子调用
- xcode - 实现一个 url sheme 协议
- c++ - 使用 RtMidi 解压 Midi 时间码
- python - 如何将 Python 可执行文件正确上传到 GitHub?
- oracle - 有没有办法让一个快速运行的查询在没有索引的列上进行过滤?
- scala - Scala 隐藏了奇怪的递归模板模式