存储最大子字符串值

时间:2016-06-21 06:13:32

标签: php laravel-5.2

$exmp = DB::table('cr_tblcomplaintregistration')
            ->select(DB::raw('MAX(CAST(SUBSTRING(complaintRegNo,16,length(complaintRegNo))+1 AS int))'))->first();
        dd($exmp);

我明白了:

{#337 ▼
  +"MAX(CAST(SUBSTRING(complaintRegNo,16,length(complaintRegNo))+1 AS int))": 51
}

如何将值51存储在另一个变量中?。

1 个答案:

答案 0 :(得分:1)

我假设问题是可变名称?如果是这样,您可以添加SQL别名:

->select(
DB::raw('MAX(CAST(SUBSTRING(complaintRegNo,16,length(complaintRegNo))+1 AS int)) AS maximum')
)

如果您希望$exmp成为列值,只需将该属性添加到链的末尾即可:

$exmp = DB::table('cr_tblcomplaintregistration')
->select(DB::raw('MAX(CAST(SUBSTRING(complaintRegNo,16,length(complaintRegNo))+1 AS int)) as maximum'))
->first()
->maximum;

当然,如果事先first()不为空,您可能希望得到。