Laravel Group By Date

后端 未结 2 446
囚心锁ツ
囚心锁ツ 2021-01-16 08:13

I am trying to make an elqouent query for a following sql,

select sum(w.total_item_count) as Day_count, w.created_at as created_at from `sales_flat_orders`          


        
相关标签:
2条回答
  • 2021-01-16 08:39
    $orderbydate = DB::table('sales_flat_orders as w')
                    ->select(array(DB::Raw('sum(w.total_item_count) as 
                    Day_count'),DB::Raw('DATE(w.created_at) as created_at')))
                    ->orderBy('w.created_at')
                    ->get();
    
    
    $orderbydate->groupBy('w.created_at');
    
    0 讨论(0)
  • 2021-01-16 08:42

    So guys, i have got the answer for this, Thank you for reading my question.

    $orderbydate = DB::table('sales_flat_orders as w')
                    ->select(array(DB::Raw('sum(w.total_item_count) as Day_count'),DB::Raw('DATE(w.created_at) day')))
                    ->groupBy('day')
                    ->orderBy('w.created_at')
                    ->get();
    

    The Raw query in my query was wrong for the created_at field. Now its good. Hope you will also get some input from this.

    0 讨论(0)
提交回复
热议问题