String sql = "select count(infection_infectionType) as infeNum, infection_infectiontype "
+" from "+ tabName
+" where infection_takendate between ? and ? " + conditions
+" group by infection_infectiontype "
+" order by infeNum DESC";
session = sessionFactory.getCurrentSession(); Query query = session.createSQLQuery(sql);
query.setString(0, fromTime);
query.setString(1, toTime);
return query.list();
每种infection_infectionType 的条数 和 infection_infectionType 名字。
然后怎么取出来 从list中取出来?
LZ可以试试
String sql = "select count(infection_infectionType) as infeNum, infection_infectiontype "
+" from "+ tabName
+" where infection_takendate between ? and ? " + conditions
+" group by infection_infectiontype "
+" order by infeNum DESC";
session = sessionFactory.getCurrentSession();
Query query = session.createSQLQuery(sql);
query.setString(0, fromTime);
query.setString(1, toTime);
List<Object> result = query.list();
List<InfeNumDTO> returnR = new ArrayList<InfeNumDTO>();
Iterator<Object> it = result.iterator();
while (it.hasNext()) {
InfeNumDTO ind = new InfeNumDTO();
Object[] obj = (Object[]) it.next();
int infeNum = Integer.parseInt(obj[0].toString());
ind.setInfeNum(infeNum);
ind.setInfeName(obj[1].toString());
returnR.add(ind);
}
return returnR;
解决了