@Test
public void test16() {
Session session = null;
session = HibernateUtil.openSession();
/**
* having是为group来设置条件的
*/
List<Object[]> stus = session.createQuery("select spe.name," +
"(count(stu.classroom.special.id)) from Student stu right join " +
"stu.classroom.special spe group by spe having count(stu.classroom.special.id)>150")
.list();
for(Object[] obj:stus) {
System.out.println(obj[0]+":"+obj[1]);
}
try {
session = HibernateUtil.openSession();
} catch (Exception e) {
e.printStackTrace();
} finally {
HibernateUtil.close(session);
}
}
@Test
public void test17() {
Session session = null;
session = HibernateUtil.openSession();
/**
* having是为group来设置条件的
*/
List<Object[]> stus = session.createQuery("select stu.sex,spe.name," +
"(count(stu.classroom.special.id)) from Student stu right join " +
"stu.classroom.special spe group by spe,stu.sex")
.list();
for(Object[] obj:stus) {
System.out.println(obj[0]+":"+obj[1]+","+obj[2]);
}
try {
session = HibernateUtil.openSession();
} catch (Exception e) {
e.printStackTrace();
} finally {
HibernateUtil.close(session);
}
}
Hibernate_HQL查询_Demo(补充)
最新推荐文章于 2020-05-23 17:10:21 发布