Mysql 其中条件不适用于聚合函数
我正在尝试使用下面的查询从表中选择数据Mysql 其中条件不适用于聚合函数,mysql,Mysql,我正在尝试使用下面的查询从表中选择数据 SELECT COUNT(*) AS totalcount,SUM(English) as EnglishTotal, SUM(Tamil) as TamilTotal,SUM(Maths) as MathsTotal, SUM(EVS) as EVSTotal,SUM(Science) as ScienceTotal from StudentMarks where Class='"+Classs+"' and Section='"+Section+"
SELECT COUNT(*) AS totalcount,SUM(English) as EnglishTotal,
SUM(Tamil) as TamilTotal,SUM(Maths) as MathsTotal,
SUM(EVS) as EVSTotal,SUM(Science) as ScienceTotal
from StudentMarks where Class='"+Classs+"'
and Section='"+Section+"' and ExamType='"+Exam+"' GROUP BY Section;
我的桌子:
如果我用下面的ResultSet
检查上述查询
if(!rscount.isBeforeFirst()){
System.out.println("Cominggggg iffff");
}
else{
System.out.println("Cominggggg elsee");
}
即使不满足条件,条件也总是转到其他部分
注意:如果我将查询更改为SELECT*from StudentMarks,其中Class='“+Classs+”,Section='“+Section+”,ExamType='“+Exam+”代码>那么它工作得很好
有人能告诉我哪里做错了吗?请尝试下面的查询
SELECT COUNT(*) AS totalcount,SUM(English) as EnglishTotal,
SUM(Tamil) as TamilTotal,SUM(Maths) as MathsTotal,
SUM(EVS) as EVSTotal,SUM(Science) as ScienceTotal
from StudentMarks where Class='"+Classs+"'
and Section='"+Section+"' and ExamType='"+Exam+"' GROUP BY Section;
我在where条件后添加了group by子句。在where子句后使用group by子句。即group by(Sno)参见规范化。RDBMS表不是电子表格