private void doSelectMax(ScheduleForm myform) throws SQLException{
String sql = "select score,[name] from score_aa " +
"where score in((select max(score) max from score_aa),(select min(score) min from score_aa)) " +"and id = trim(?)";
PreparedStatement ps = myform.getConn().prepareStatement(sql);
ps.setString(1,myform.getSubjectId());
ResultSet rs = ps.executeQuery();
while(rs.next()){
myform.setMaxscore(rs.getString("max"));
myform.setMinscore(rs.getString("min"));
}
}现有这么一段程序,用上面的方法只能取得最高分和最低分,但是如何取得他们相对应的学生姓名呢?在数据库里用上面的SQL文可以得到最高分最低分和他们相对应的名字。
String sql = "select score,[name] from score_aa " +
"where score in((select max(score) max from score_aa),(select min(score) min from score_aa)) " +"and id = trim(?)";
PreparedStatement ps = myform.getConn().prepareStatement(sql);
ps.setString(1,myform.getSubjectId());
ResultSet rs = ps.executeQuery();
while(rs.next()){
myform.setMaxscore(rs.getString("max"));
myform.setMinscore(rs.getString("min"));
}
}现有这么一段程序,用上面的方法只能取得最高分和最低分,但是如何取得他们相对应的学生姓名呢?在数据库里用上面的SQL文可以得到最高分最低分和他们相对应的名字。
楼主【darkhrt】截止到2008-07-31 10:54:52的历史汇总数据(不包括此帖):
发帖的总数量:1 发帖的总分数:0 每贴平均分数:0
回帖的总数量:1 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:1 结贴的总分数:0
无满意结贴数:0 无满意结贴分:0
未结的帖子数:0 未结的总分数:0
结贴的百分比:100.00% 结分的百分比:---------------------
无满意结贴率:0.00 % 无满意结分率:---------------------
敬礼!
取消马甲机器人,请点这里:http://www.java2000.net/mycsdn/robotStop.jsp?usern=darkhrt
myform.setMinscore(rs.getString("min"));
改为 myform.setMaxscore(rs.getString("score"));
myform.setMinscore(rs.getString("name"));
int i=0;
while(rs.next()){
if(i==0){
myform.setMinscore(rs.getString("score"));
i++;
}
else
myform.setMaxscore(rs.getString("score"));
name =rs.getString("name")
}
user{
name,score
}user.setScore(rs.getString('score'));
user.setName(rs.getString('name'));
myform.setMax(user);