HQL问题,session取出两个值后放到List中如何取出呢?(内有详情)
交谈中请勿轻信汇款、中奖信息、陌生电话,勿使用外挂软件。
package cn.jbit.dao;
import java.util.*;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import cn.jbit.*;
import cn.jbit.dao.District;
import cn.jbit.dao.Street;
public class HibernateTest1 {
public static void main(String[] args) {
/*//sum函数
select sum(house.floorage) from House house group by house.street_id having sum(house.floorage) > 1000
//count函数
select count(house) from House house where house.user_id = '1010'
//max函数
select max(house.price),min(house.price) from House house
//avg函数
select avg(house.price),sum(house.floorage) from House house where house.user_id = '1000'*/
SessionFactory sessionFactory = new Configuration().configure()
.buildSessionFactory();
Session session = sessionFactory.openSession();
// String hql = "select count(house) from House house where house.title="好房"";
Query query = session.createQuery("select max(house.price)as x,min(house.price) as y from House house ");
List<List> list = query.list();
for (int i=0;i<list.size();i++){
double double1=Double.valueOf(list.get(i).get(0));
System.out.println(double1);
}
// Iterator it = list.iterator();
//
// if (it.hasNext()) {
// double max;
// System.out.println();
// }
session.close();
sessionFactory.close();
}
}
当然把查询语句分开写是没问题的,但是琢磨着把两条语句放到一起就不行了,试了好几种方法都没有办法输出正确结果,如何能把house.price的最大值最小值得到呢?
就是想把最大值最小值用一条语句取出来,并且能正确的输出。 麻烦各位大侠了!谢谢!~~ --------------------编程问答-------------------- select t1.x,t2.y from (select max(house1.price)as x,from House house1) t1,
(select min(house2.price) as y from House house2) t2
试一下。
补充:Java , Java SE