laravel query php how to get max value within a range

泪湿孤枕 提交于 2019-12-04 07:53:25

Try to use whereBetween hope this works:

$max_scores_table= DB::table('scores_table')
    ->select(DB::raw('MAX(score) FROM scores_table as MaxScore'))
    ->whereBetween('id', array(3,5))
    ->where('score', 'MaxScore')
    ->get();

OR:

$max_scores_table= DB::table('scores_table')
    ->whereBetween('id', array(3,5))
    ->max('score')
    ->get();

Write query as below(tested):

$max_scores_taable = DB::table('scores_table)
                     ->whereBetween('id',array(3,5))
                     ->max('score')

Reference : Laravel API

Use query like this

$max_scores_table = DB::table('scores_table')
                    ->whereBetween('id', array(3, 5))->max('score')->get();

For your reference just follow Laravel Documentation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!