我有一个表,除其他列外,还包含一列浏览器版本。我只是想从记录集中知道每种类型的浏览器有多少个。
我的代码是:
$whereBrowser = [['owner', '=', 12]];
$browser = ProfileTracker::where($whereBrowser)->whereBetween('created_at', [Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth()])->select([
DB::raw('browser'),
DB::raw('COUNT(browser) as value')
])->groupBy("browser")->orderBy("value", "desc")->take(10)->get();
输出 :
"browser": [
{
"browser": "Chrome Mobile 84",
"value": 144
},
{
"browser": "Chrome Mobile 80",
"value": 84
},
{
"browser": "Chrome 84",
"value": 27
},
{
"browser": "Chrome 30",
"value": 22
},
{
"browser": "Chrome Mobile 83",
"value": 19
},
{
"browser": "Chrome Mobile 47",
"value": 10
},
{
"browser": "Firefox 79",
"value": 8
},
{
"browser": "Mobile Safari",
"value": 8
},
{
"browser": "Mobile Safari 13.1.2",
"value": 6
}
],
}
我想对所有浏览器进行分组,没有浏览器版本,如下所示:
"browser": [
{
"browser": "Chrome",
"value": 306
},
{
"browser": "Safari",
"value": 14
},
{
"browser": "Firefox",
"value": 8
},
],
}
慕仙森
心有法竹