[英]Get the Max Value in MySQL in Laravel
Here is my Query in Laravel 这是我在Laravel中的查询
$salename = DB::table('home_sc')->where('OrderNo', $orderno)->pluck('salesconfirmation');
Here i am using pluck, where it will get the salesconfirmation with the $orderno. 在这里,我使用的是pluck,它将通过$ orderno获得销售确认。
But how can i get the salesconfirmation for the max $orderno 但是我如何获得最大$ orderno的销售确认书
Update: OrderNo is not Unique or an Auto Increment, the table however, has another field named ID, this is the field for which I need to retrieve to max value of. 更新: OrderNo不是唯一或自动递增,但是表中还有另一个名为ID的字段,这是我需要检索到其最大值的字段。
Assuming that OrderNo
is an incremental value, you could do this: 假设OrderNo
是一个增量值,则可以执行以下操作:
DB::table('home_sc')->orderBy('ID', 'DESC')->where('OrderNo', $orderno)
->take(1)->pluck('salesconfirmation');
Also, just a sidenote, but it may be worth considering a change to the database structure, as you've got three naming conventions in this query alone. 另外,仅作一个旁注,但可能值得考虑更改数据库结构,因为仅在此查询中就有三种命名约定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.