laravel两个日期之间查询错误语法错误

laravel between two dates query error Syntax error

请帮助我查询。我目前收到查询错误。我是 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,因为我怀疑是不是语法错误的人。

错误:

Syntax error or access violation: 1064

知道了!您在 between 子句中缺少 ):

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

立即尝试