laravel查询查找过去7天内每天所有注册用户的sum view count

4xrmg8kj  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(290)

在我的视图计数表中,我想找出过去7天中所有注册用户每天的点击量总和。这是我的table:

这是我使用的查询

$RegHits = Visitor::distinct('date_visited')
->whereDate('date_visited', '>=' , Carbon::now()->subDays(7))
->whereNotNull('user_id')
->pluck('hits')
->toArray();

这得到一个[15,13,6,1,4,10]数组
如何获得点击总数数组在这种情况下,我的预期结果应该是:
[55 , ? , ? , ? , ? , ? , ?] 过去7天中的每一天

suzh9iv8

suzh9iv81#

此代码适用于我:

Visitor::selectRaw('date_visited, Sum(hits)')
->groupBy('date_visited')
->whereNotNull('user_id')
->whereDate('date_visited', '>=' , Carbon::now()->subDays(7))
->pluck('Sum(hits)')
->toArray();

我得到的是过去7天每天所有注册点击量的总和:[55,,?,?,?,?,?]

相关问题