【发布时间】:2018-03-21 15:58:16
【问题描述】:
请在我的查询中帮助我。我目前收到查询错误。我是 laravel 的新手,我不知道如何将我的查询变成 laravel 查询。这是我的查询:
$date1 = date("Y-m-d", strtotime($request->datepicker));
$date2 = date("Y-m-d", strtotime($request->datepicker1));
$products = DB::table('shipping_table')
->select('products.product_name', 'products.price', DB::raw('Sum(shipping_products.quantity) AS qtysold'), 'shipping_table.sold_date')
->join('shipping_products','shipping_table.shipping_id', '=', 'shipping_products.shipping_id')
->join('products','products.product_id', '=', 'shipping_products.product_id')
->where(['shipping_table.shipping_status', '=' ,1])
->whereBetween(DB::raw("date(shipping_table.sold_date"),[$date1,$date2])
->groupBy('products.product_name')
->get();
请查看whereBetween,因为我怀疑是不是语法错误。
错误:
语法错误或访问冲突:1064
【问题讨论】:
-
我认为您的问题出在
date(shipping_table.sold_datein whereBetween!格式和$date1 = date("Y-m-d", strtotime($request->datepicker));一样,先看看这个! -
你能把
$date1 = date("Y-m-d", strtotime($request->datepicker));的结果打印出来,你得到的究竟是什么格式? -
是
2017-10-09还是string(10) "2017-10-09"??? -
@HirenGohel 其字符串(10)“2017-10-09”
-
date(shipping_table.sold_date)是什么格式,和$date1格式一样吗?
标签: mysql sql laravel laravel-5.4 laravel-query-builder