我想给学生打分,所以需要除以最高分是各自的科目。 一旦我想除以最小的也没有。我不想做多个查询。
这是表格
id name physics math
1 Adam 68 80
2 Mark 55 97
3 Luis 78 44
4 Philip 99 62
5 James 59 89
我的php代码是
$re99 = "SELECT * FROM `tableA` order by id desc limit 10";
while($row2 = $res2->fetch_assoc()){
$name=$row2['name'];
$physics=$row2['physics'];
$math=$row2['math'];
$grade=$physics/99+$math/97;
$poor='poor performer in math is mark with 55 marks and Luis with 44 marks';
}
我不知道如何在一次查询中从上表中获取这 4 个值 (99,97,55,44)
最佳答案
如何选择 *, max(physics) as high_physics, max(math) as high_math, min(physics) as min_physics, min(math) as min_math from tableA order by id desc limit 10;
然后你可以做类似$grade = $physics/$row2['high_physics'] + $math/$row2['high_math'];
关于php - 从 mysql 单元格中除以最高值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39276775/