看看上面的图片。
我想要的是使用上面的数据库创建一个每周数据表。从上周开始(从今天到 7 天前)。该表应包含dish_name
, Sum of quantity
for last week, sum of price
for last week group by dish_name
。
任何人都可以为此提供解决方案。(使用 Laravel 5.7
)
$today = Carbon::now();
$one_week_ago = Carbon::now()->subWeeks(1);
$something = BillPaid::where('created_at', '>=', $one_week_ago)
->where('created_at', '<=', $today)
->select('dish_name', 'quantity')->groupBy('dish_name')->get();
问题不是获取日期。我可以清楚地从上面的查询中获得产品。我不知道在那之后我必须做什么。从上图中,我附上了过去一周的时间,2018-12-28 to 2018-12-21
因此该图像中的所有记录都应包括在内。
我想要的是制作一张像:
"vege rice" , 3 (quatation), 600(price) ,
"Chicken Fried rice", 9(quatation), 3150 (price)
试试这个代码:
$today = Carbon::now();
$one_week_ago = Carbon::now()->subWeeks(1);
$something = BillPaid::selectRaw('dish_name,SUM(price) as totalPrice,SUM(quantity) as totalQuantity')
->whereBetween('created_at', [$one_week_ago, $today])
->groupBy('dish_name')->get();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句