laravel中如何使用selectRaw和group by
<?php
$data = Table::select('id','tag_id','name',\DB::raw('id+1 as new_id'))->selectRaw('id+tag_id as id_tag_id')->selectRaw("concat(id,'---',tag_id) as cnt")->where('tag_id',$id)->get();
echo "<pre>";
print_r($data->toArray());
$data = Table::select(\DB::raw('DATE(created_at) as year, COUNT(*) as amount'))->where('tag_id',$id)->groupBy(\DB::raw('date(created_at)'))->first();
echo "<pre>";
print_r($data->toArray());
?>
如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术
转载请注明:laravel中selectRaw查询 出自老鄢博客 | 欢迎分享