我将 Java 与 SQL 以及 Oracle 数据库结合使用来从我上传的电子表格中检索内容。如果我有一列包含每个学生的姓名,并且有一列包含他们的平均值,并且想要获得整个班级的平均值,例如,然后检查单个学生的平均值是否大于班级平均值并将这些在单独的桌子上满足这些标准的学生,我将如何去做?我有一个想法,但我不确定这是否正确。如我错了请纠正我。
//Select student averages so I can get each student's individual score
resultset = st.executeQuery("SELECT Student_Averages FROM table");
//Get the class average
stavg = "SELECT Avg(Student_Averages)) AS classAverage FROM table";
rs = st.executeQuery(stavg);
//Iterate through their individual scores and store them in a float variable to
//compare them later.
while(resultset.next()){
float studentaverage = resultset.getFloat("Student_Averages");
}
//Store the class average in a float variable
float classaverage = stavg.getFloat("Student_Averages");
//Compare the individual student average to the class average
if(studentaverage >= classaverage){
//Generate new table with student names
}
我是使用数据库的新手。我不确定如何使用符合要求的学生的姓名生成一个新表。我将不胜感激任何帮助!