mysql - 语法错误: missing `closing parenthesis` MySQL

标签 mysql sql

I don't know way I got this error message here:

enter image description here

这是查询:

SELECT t1.*,t2.totalAvg, ABS(`average for this subject`-totalAvg)  AS Difference, 100*MIN(`average for this subject`,totalAvg)/MAX(`average for this subject`,totalAvg) AS precent
FROM (SELECT StudentFirstName,StudentLastName,ClassName,AVG(Grade) AS `average for this subject`
      FROM tests
      INNER JOIN students ON tests.StudentID=students.StudentID
      GROUP BY StudentFirstName,StudentLastName,ClassName
     ) t1
JOIN (SELECT StudentFirstName,StudentLastName,AVG(`average for this subject`) as totalAvg
      FROM (SELECT StudentFirstName,StudentLastName,ClassName,AVG(Grade) AS `average for this subject`
            FROM tests
            INNER JOIN students ON tests.StudentID=students.StudentID
            GROUP BY StudentFirstName,StudentLastName,ClassName
           ) t
      GROUP BY StudentFirstName,StudentLastName
     ) t2 
ON t1.StudentFirstName=t2.StudentFirstName and t1.StudentLastName=t2.StudentLastName

最佳答案

你的代码可能还有其他错误,但这在MySQL中肯定是不正确的:

MIN(`average for this subject`, totalAvg)

MIN() 仅采用一个参数。想必,您想要 LEAST():

LEAST(`average for this subject`, totalAvg)

关于mysql - 语法错误: missing `closing parenthesis` MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47722921/

相关文章:

MySQL条件查询

sql - sp_send_dbmail 中的局部变量?

python - 无法在事务中执行备份或还原操作

sql级联删除

mysql - 500个搜索引擎索引,每个都需要计算。如何扩展?

php - 从两个表中选择并计算有多少条评论已发布

mysql - 使用来自单独 MySQL 表的 2 列计算平均时间

java - Mybatis如何在xml中动态创建表sql

sql - ORA-00205 : error in identifying control file, 检查警报日志以获取更多信息

php - 从数据库中获取数据并 2 乘 2 地组织它