gpt4 book ai didi

mysql - laravel between two dates query error 语法错误

转载 作者:行者123 更新时间:2023-11-30 21:52:25 28 4
gpt4 key购买 nike

请帮助我查询。我目前收到查询错误。我是 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();

立即尝试

关于mysql - laravel between two dates query error 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46663429/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com