我仅从datetime
选择月份部分时遇到问题。我在表格事务中有一个名为 payment_date 的列。我希望 payment_date select * from transaction
和group by
个月。我试过这段代码:
$selectedYearTrx = $connectDB->table('transaction')
->join('payment_channel','transaction.payment_channel_id','=','payment_channel.id')
->select('id','payment_date', 'payment_channel_id','amount',DB::raw('MONTH(payment_date) as monthPayment'))
->whereYear('payment_date', '=', $year)
->where('status','=','S')
->wherein('payment_channel_id', [1,2,3])
->where('currency','=','IDR')
->orderBy('id', 'desc')
->get()
->groupBy('payment_channel_id','id','monthPayment');
但是,我在群组monthPayment
中收到错误。错误是调用成员函数 groupby()。
任何人都可以帮我解决这个问题吗?
谢谢。
答案 0 :(得分:0)
你应该在代码的末尾加上 - > get())
$selectedYearTrx = $connectDB->table('transaction')
->join('payment_channel','transaction.payment_channel_id','=','payment_channel.id')
->select('id','payment_date', 'payment_channel_id','amount',DB::raw('MONTH(payment_date) as monthPayment'))
->whereYear('payment_date', '=', $year)
->where('status','=','S')
->wherein('payment_channel_id', [1,2,3])
->where('currency','=','IDR')
->orderBy('id', 'desc')
->get()
->groupBy('payment_channel_id','id','monthPayment');
应该是
$selectedYearTrx = $connectDB->table('transaction')
->join('payment_channel','transaction.payment_channel_id','=','payment_channel.id')
->select('id','payment_date', 'payment_channel_id','amount',DB::raw('MONTH(payment_date) as monthPayment'))
->whereYear('payment_date', '=', $year)
->where('status','=','S')
->wherein('payment_channel_id', [1,2,3])
->where('currency','=','IDR')
->orderBy('id', 'desc')
->groupBy('payment_channel_id','id','monthPayment')->get();