select top改写成mysql数据库支持的语句
publicList<String>exampaper(inta,intb,intc,intd,inte)throwsSQLException{List<String>l...
public List<String> exampaper(int a,int b ,int c ,int d,int e) throws SQLException{
List<String> list =new ArrayList<String>();
this.dbsConnection();
String sql1 ="select top "+ a+" exid from itempool where type='exam' and exty='choose' Order By NewID()";
rs = stmt.executeQuery(sql1);
while(rs.next()){
list.add(rs.getString(1));
}
String sql2 ="select top "+ b+" exid from itempool where type='exam' and exty='judge' Order By NewID()";
rs = stmt.executeQuery(sql2);
while(rs.next()){
list.add(rs.getString(1));
}
String sql3 ="select top "+ c+" exid from itempool where type='exam' and exty='fill' Order By NewID()";
rs = stmt.executeQuery(sql3);
while(rs.next()){
list.add(rs.getString(1));
}
String sql4 ="select top "+ d+" exid from itempool where type='exam' and exty='shorta' Order By NewID()";
rs = stmt.executeQuery(sql4);
while(rs.next()){
list.add(rs.getString(1));
}
String sql5 ="select top "+e+" exid from itempool where type='exam' and exty='solution' Order By NewID()";
rs = stmt.executeQuery(sql5);
while(rs.next()){
list.add(rs.getString(1));
请问上述语句该如何改写才能让mysql支持呢?菜鸟请教内行的朋友们:-D,各个题目的数量,选择填空判断10道,简答5问答8道 展开
List<String> list =new ArrayList<String>();
this.dbsConnection();
String sql1 ="select top "+ a+" exid from itempool where type='exam' and exty='choose' Order By NewID()";
rs = stmt.executeQuery(sql1);
while(rs.next()){
list.add(rs.getString(1));
}
String sql2 ="select top "+ b+" exid from itempool where type='exam' and exty='judge' Order By NewID()";
rs = stmt.executeQuery(sql2);
while(rs.next()){
list.add(rs.getString(1));
}
String sql3 ="select top "+ c+" exid from itempool where type='exam' and exty='fill' Order By NewID()";
rs = stmt.executeQuery(sql3);
while(rs.next()){
list.add(rs.getString(1));
}
String sql4 ="select top "+ d+" exid from itempool where type='exam' and exty='shorta' Order By NewID()";
rs = stmt.executeQuery(sql4);
while(rs.next()){
list.add(rs.getString(1));
}
String sql5 ="select top "+e+" exid from itempool where type='exam' and exty='solution' Order By NewID()";
rs = stmt.executeQuery(sql5);
while(rs.next()){
list.add(rs.getString(1));
请问上述语句该如何改写才能让mysql支持呢?菜鸟请教内行的朋友们:-D,各个题目的数量,选择填空判断10道,简答5问答8道 展开
1个回答
展开全部
mysql里用limit
比如,你要查前10条记录
1 | select * from 表名 order by 字段名 limit 10 |
你自己改一下吧,你说的几道几道是什么意思啊?
追问
这是从表itempool里面选择试题,就是String sql5 ="select*from itempool "+e+" order by type='exam' and exty='solution' limit13"那个order by new id还要吗
追答
order by newid() 这个应该是随机取题
在mysql中可以换成order by rand() limit 10
类似这样
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询