Laravel使用具有不同名称字段的group-by获取数据计数

时间:2017-11-29 06:29:47

标签: laravel eloquent query-builder

我理解以下查询是如何工作的。

$user_info = DB::table('usermetas')
                 ->select('browser', DB::raw('count(*) as total'),DB::raw("DATE_FORMAT(created_at,'%h:%i %p') as day")
                 ->groupBy('browser')
                 ->get();   

这将得到结果

[{"browser":"GC","total":1,"day":"04:27 AM"},{"browser":"GC","total":2,"day":"04:27 AM"},
{"browser":"MF","total":1,"day":"05:27 AM"},
{"browser":"MF","total":1,"day":"07:27 AM"}]

是否可以获得结果输出。

[{"browser":"GC","total":1,"day":"04:27 AM"},{"browser":"GC","total":2,"day":"04:27 AM"},
{"browser":"MF","total_test":1,"day":"05:27 AM"},
{"browser":"MF","total_test":1,"day":"07:27 AM"}]

我们可以为计数字段指定不同的名称吗?

0 个答案:

没有答案