我在RAW
Laravel
个查询
$sales = DB::table('orders')
->select(DB::raw('DATE(created_at) as date'),
DB::raw('SUM(total_price) AS total_price'),
'created_at')
->groupBy('date')
->orderBy('date', 'DESC')
->paginate(20);
我正在尝试对结果集进行分页,但它向我显示以下错误;
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'date' in 'group statement'
(SQL: select count(*) as aggregate from `orders` group by `date`)
上面的查询工作正常,并在我替换时返回完整的结果集;
带有paginate(20)
的 get()
发生了什么事?
答案 0 :(得分:0)
$sales = DB::table('orders')
->select(DB::raw('DATE(created_at) as `date`'),
DB::raw('SUM(total_price) AS total_price'),
'created_at')
->groupBy('date')
->orderBy('date', 'DESC')
->paginate(20);
尝试使用此代码,它应该可以正常工作。