Mysql 两个日期之间的LAVEL查询错误语法错误

Mysql 两个日期之间的LAVEL查询错误语法错误,mysql,sql,laravel,laravel-5.4,laravel-query-builder,Mysql,Sql,Laravel,Laravel 5.4,Laravel Query Builder,请帮我查询一下。我当前收到一个查询错误。我是拉雷维尔的新手,我不知道如何将我的查询转换成拉雷维尔查询。我的问题是: $date1 = date("Y-m-d", strtotime($request->datepicker)); $date2 = date("Y-m-d", strtotime($request->datepicker1)); $products = DB::table('shipping_table') ->

请帮我查询一下。我当前收到一个查询错误。我是拉雷维尔的新手,我不知道如何将我的查询转换成拉雷维尔查询。我的问题是:

$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


明白了!您的中间条款中缺少一个(a):

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

现在试试看

明白了!您的中间条款中缺少一个(a):

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

现在试一试

我想你的问题出在日期上(发货表。销售日期在哪之间!格式与日期相同(
$date1=date(“Y-m-d”,strotime($request->datepicker));
首先检查这个!你能打印日期的结果吗(“Y-m-d”,strotime($request->datepicker))您得到的确切格式是什么?是
2017-10-09
还是
string(10)“2017-10-09”
?@HirenGohel其string(10)“2017-10-09”日期的格式是什么(发货表.售出日期)与
$date1
格式相同吗?我想您的问题在于
日期(shipping_table.Sald_date
在哪之间!格式与
$date1=date(“Y-m-d”,strtotime($request->datepicker));
首先检查这个!您能打印
$date1=date(“Y-m-d”,strtotime($request->datepicker))的结果吗?
您得到的确切格式是什么?是
2017-10-09
还是
字符串(10) “2017-10-09”
?@HirenGohel its string(10)“2017-10-09”日期(shipping\u table.selled\u date)的格式与
$date1
格式相同吗?SQLSTATE[42000]:语法错误或访问冲突:1064您的SQL语法有错误;格式已经很好,先生这里是var\u dump($date1);string(10)“2017-10-09”您使用的是严格模式吗?您可以在数据库连接配置数组(
database.php
config文件)中检查它。您好,thnks先生,请快速回复。我已经将严格模式设置为Falstal500内部服务器错误SQLState[42000]:语法错误或访问冲突:1064您的SQL语法有错误;它的格式已经很好了,先生这里是var_dump($date1);string(10)“2017-10-09”您使用的是严格模式吗?您可以在数据库连接配置数组(
database.php
config文件)中检查它您好,先生,请快速回复。我已经做了严格模式错误,但仍然有500个内部服务器错误