2014-10-28 102 views
0

我試圖使一個如下的sql的elqouent查詢,Laravel集團按日期

select sum(w.total_item_count) as Day_count, w.created_at as created_at from `sales_flat_orders` as `w` group by DATE(`w`.`created_at`) order by `w`.`created_at` asc 

,我曾嘗試在SQL查詢這個

$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'))) 
       ->groupBy('w.created_at') 
       ->orderBy('w.created_at') 
       ->get(); 

我得到正確的輸出,但不雄辯的查詢, 請幫忙,謝謝。

回答

5

所以大家好,我已經得到了答案,謝謝你閱讀我的問題。

$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(); 

我的查詢中的原始查詢對於created_at字段是錯誤的。現在它很好。希望你也會從中得到一些輸入。