我正在尝试使用以下查询记录最近7天的记录,但是它不起作用。
<?php
DB::table('data_table')
->select(DB::raw('SUM(fee) as counter, left(DATE(created_at),10) as date'))
->whereIn('user_id', $descendants)
->whereRaw('DATE(created_at) = DATE_SUB(CURDATE(), INTERVAL 7 DAY)')
->groupBy(DB::raw('left(DATE(created_at),10)'))
->get();
如何使其正确?
答案 0 :(得分:1)
-> where('created_at','> =',Carbon \ Carbon :: now()-> subDays(7)-> startOfDay())-> get()