你好我如何获得分数的最大值,其中列 ID 范围从 3-5 开始 示例表
我想得到scores的最大值,其中column ID的范围是3-5 , 请帮助,
到目前为止我做了什么:
$max_scores_table= DB::table('scores_table')
->where('id', '>', 2)
->max('score');
另一个问题是当我在表格中有小数点时 当我使用 max() 函数时,它得到的是 ID=5,它的分数是 4.5,而不是 ID=4,值为 4.6,提前 tnx
最佳答案
尝试使用 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();
关于php - laravel query php 如何获取一个范围内的最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32448857/