已解决SQL_ERROR_INFO: “You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘.difficult_level\n (count(q1.question_id)/count(distinct q1.device_id)) as avg’ at line 3”


文章目录


报错代码

粉丝群一个小伙伴的代码如下


select 
    u.university
    q2.difficult_level
    (count(q1.question_id)/count(distinct q1.device_id)) as avg_answer_cnt
    
from  
    user_profile  as u 
    join question_practice_detail as q1 on u.device_id = q1.device_id
    join question_detail as q2 on q1.question_id = q2.question_id

where 
    university = '山东大学'
group by q2.difficult_level

报错信息:

SQL_ERROR_INFO: “You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘.difficult_level\n (count(q1.question_id)/count(distinct q1.device_id)) as avg’ at line 3

在这里插入图片描述

报错翻译

报错内容翻译

SQL\u ERROR\u INFO:“您的SQL语法有错误;请查看与您的MySQL server版本对应的手册,以了解要在附近使用的正确语法。第3行的平均值为\u级(count(q1.question\u id)/count(distinct q1.device\u id))

报错原因

报错原因:您的SQL语法有错误;请查看与您的MySQL server版本对应的手册

解决方法

SQL_ERROR_INFO: "You have an error in your SQL syntax; check the manual that corresponds to your...类似这种开头的错误,这种错误一般情况下就是多个标点符号啊,字段名字写错了等一系列因为手打失误出现的错误。

检查一下代码发现少了两个逗号:

在这里插入图片描述

修改代码后运行成功:

select 
    u.university,
    q2.difficult_level,
    (count(q1.question_id)/count(distinct q1.device_id)) as avg_answer_cnt
from  
    user_profile  as u 
    join question_practice_detail as q1 on u.device_id = q1.device_id
    join question_detail as q2 on q1.question_id = q2.question_id

where 
    university = '山东大学'
group by q2.difficult_level

帮忙解决

本文已收录于:

本专栏用于记录学习和工作中遇到的各种疑难Bug问题,以及粉丝群里小伙伴提出的各种问题,文章形式:报错代码 + 报错翻译 + 报错原因 + 解决方法,包括程序安装、运行程序过程中等等问题,订阅专栏+关注博主后如遇到其他问题可私聊帮忙解决!!!