以下查询在MySQL提示符中正确执行但是在Java中出错 (您的SQL语法有错误;请查看与您的MySQL服务器版本对应的手册,以便在'by附近使用正确的语法(选择avg时的案例等级,然后当'A'时为4,然后当'A'时为4 - '然后在第1行3.7 w'
java.sql.ResultSet rslt= stmt.executeQuery("select name from student natural join takes t1 where (dept_name='Comp. Sci.')" +
"group by ID" +
"order by (select avg( case grade " +
"when 'A+' then 4 " +
"when 'A' then 4 " +
"when 'A-' then 3.7 " +
"when 'B+' then 3.5 " +
"when 'B' then 3 " +
"when 'B-' then 2.7 " +
"when 'C+' then 2.5 " +
"when 'C' then 2 " +
"when 'C-' then 1 " +
"end) as avg_gpa " +
"from takes t2 " +
"where t1.ID=t2.ID) " +
"limit 10");
有人可以帮忙吗?
答案 0 :(得分:0)
不要忘记每行后面的空格:
java.sql.ResultSet rslt= stmt.executeQuery(
"select name from student natural join takes t1 where (dept_name='Comp. Sci.') "+
"group by ID "+
"order by (select avg( case grade "+
"when 'A+' then 4 "+
"when 'A' then 4 "+
"when 'A-' then 3.7 "+
"when 'B+' then 3.5 "+
"when 'B' then 3 "+
"when 'B-' then 2.7 "+
"when 'C+' then 2.5 "+
"when 'C' then 2 "+
"when 'C-' then 1 "+
"end) as avg_gpa "+
"from takes t2 "+
"where t1.ID=t2.ID) "+
"limit 10");
你的sql错了:
"group by ID" +
"order by (select avg( case grade " +
这里有一个像这样的字符串:"group by IDorder by (select avg( case grade"
在ID