hello how do i get the max value of scores, where column ID range starts at 3-5 example table
您好,我如何获得分数的最大值,其中列ID范围从3-5示例表开始
I want to get the max value of scores, where column ID ranging from 3-5 , please help,
我想获得分数的最大值,其中列ID范围从3-5,请帮忙,
what I have done so far:
到目前为止我做了什么:
$max_scores_table= DB::table('scores_table')
->where('id', '>', 2)
->max('score');
another problem is when i have a decimal points in the table when I used the max() function it gets the ID=5, which has a Score of 4.5, instead of ID=4 with a value of 4.6, tnx in advance
另一个问题是,当我使用max()函数时表中有小数点时,它得到ID = 5,得分为4.5,而不是ID = 4,值为4.6,tnx提前
3 个解决方案
#1
5
Try to use whereBetween
hope this works:
尝试使用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();
OR:
要么:
$max_scores_table= DB::table('scores_table')
->whereBetween('id', array(3,5))
->max('score')
->get();
#2
1
Write query as below(tested):
写下查询(测试):
$max_scores_taable = DB::table('scores_table)
->whereBetween('id',array(3,5))
->max('score')
Reference : Laravel API
参考:Laravel API
#3
0
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
仅供参考Laravel文档
#1
5
Try to use whereBetween
hope this works:
尝试使用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();
OR:
要么:
$max_scores_table= DB::table('scores_table')
->whereBetween('id', array(3,5))
->max('score')
->get();
#2
1
Write query as below(tested):
写下查询(测试):
$max_scores_taable = DB::table('scores_table)
->whereBetween('id',array(3,5))
->max('score')
Reference : Laravel API
参考:Laravel API
#3
0
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
仅供参考Laravel文档