简体   繁体   English

Select 并在报告中添加按月和年分隔的记录

[英]Select and add records separating by month and year in report

I am using LaraCharts and I need to select in a report the sum total related to that month and year in the records.我正在使用 LaraCharts,我需要 select 在报告中记录与该月份和年份相关的总和。

$value = DB::table('values')
        ->join('users', 'users.id', '=', 'value.id_loja')
        ->join('clients', 'clients.id', '=', 'value.id_cliente')
        ->GROUPBY (YEAR(`due_date`),MONTH(`due_date`))
        ->get();
        $total_value = $value->sum('cust');

This example I used groupby.这个例子我使用了 groupby。 and it's returning me error.它返回给我错误。

Call to undefined function App\Http\Controllers\YEAR()

Use DB::raw() to use mysql functions使用 DB::raw() 来使用 mysql 函数

->GROUPBY (DB::raw('YEAR(due_date)'), DB::raw('MONTH(price)')

More here:更多在这里:

https://laravel.com/docs/7.x/queries#raw-expressions https://laravel.com/docs/7.x/queries#raw-expressions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM