你好,如何获取分数的最大值,列ID范围从3-5开始的示例表

我想获取分数的最大值,其中列ID为3-5,请帮助。
到目前为止,我所做的是:
$max_scores_table= DB::table('scores_table')
->where('id', '>', 2)
->max('score');另一个问题是,当我在表中有一个小数点时,当我使用max()函数时,它会预先得到得分为4.5的ID=5,而不是值为4.6的ID=4
发布于 2015-09-08 11:41:04
试着使用whereBetween希望这能行得通:
$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();或者:
$max_scores_table= DB::table('scores_table')
->whereBetween('id', array(3,5))
->max('score')
->get();发布于 2015-09-08 11:48:57
如下所示编写查询:
$max_scores_table = DB::table('scores_table')
->whereBetween('id',array(3,5))
->max('score');参考: Laravel API
发布于 2015-09-08 13:23:02
像这样使用查询
$max_scores_table = DB::table('scores_table')
->whereBetween('id', array(3, 5))->max('score')->get();只需关注Laravel Documentation即可作为参考
https://stackoverflow.com/questions/32448857
复制相似问题