php - 从 mysql 单元格中除以最高值

标签 php mysql

我想给学生打分,所以需要除以最高分是各自的科目。 一旦我想除以最小的也没有。我不想做多个查询。

这是表格

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/

相关文章:

php - 无法用文本更新mysql数据库

mysql - 如何修复 SSIS 中的 ODBC Driver 8.0 SQL 语法错误?

php - Ajax 请求在 Meteor 中失败,但在 localhost 测试中正确

php - mySQL 查询 - 如何?

php - jQuery AJAX post 正在更改 post 数据中的字符

php - 如何使用php比较sql中的多个复选框值?

php - CakePHP 本地化无法工作

php - 循环遍历 MySQL 结果并将值保存到 $_SESSION

mysql - 我需要一个统一多个插入的程序

php - PDO 查询绑定(bind)字符串而不是整数返回结果