直接上代码,仅供参考
String sql = "select res.hospital.hoscode,count(res) from Reservation res,Hospital hos where res.reservedtime between to_date('2009-2-20','yyyy-MM-dd') and to_date('2010-12-20','yyyy-MM-dd') and hos.hosonline='1' group by res.hospital.hoscode order by count(res) ";
EntityManager em = EntityManagerHelper.getEntityManager();
Query query = em.createQuery(sql);
List list = query.getResultList();
Iterator it = list.iterator();
while(it.hasNext())
{
Object[] obj = (Object[]) it.next();
System.out.print(obj[0]);
System.out.println(" "+obj[1]);
}
em.close();
来源:http://hi.baidu.com/mqchange/blog/item/ece87d3d7175432d71cf6cea.html