【发布时间】:2020-11-09 09:48:56
【问题描述】:
我有两个不同的表('product', 'quantity_break') 每个表都有一个与'product_code' 数量表的连接每个`product_code 有多个数量和价格。
所以我只需要显示('product_code','product_name',max(quantity),maximum quantity price)。
请帮助我如何在 Laravel 中进行查询。
产品表视图
id product_code product_name
1 123 Testing
2 1234 Testing 1234
quantity_break 表格视图
id qty_pro_code qty price
1 123 50 20.00
2 123 60 18.00
3 123 70 15.00
4 1234 50 25.00
5 1234 60 23.00
这是我想要获取 product_code 123 数量 70 价格 (15.00) 和 product_code 1234 数量 70 价格 (23.00) 的每个表格的表格视图
这就是我尝试查询的方式
$arr["product"] = DB::table('product')
->join('quantity_break', 'quab_product_code', '=', 'prod_product_code')
->select('product.prod_product_code','product.product_name','quantity_break.quab_product_code','quantity_break.quab_quantity','quantity_break.quab_price')
->max('quantity_break.quab_quantity')
->get();
但它是这样的给予和错误
Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR)
Call to a member function get() on integer
【问题讨论】:
-
您应该可以查询表格并按产品代码分组并按价格排序。你能举例说明你是如何尝试这个问题的吗?