Render401 2019-04-18 22:27 采纳率: 0%
浏览 1890

HQL多表查询,多条件查询语句

一、题目内容
Student(id,name,age,StudentCard)
StudentCard(id,cardNumber)
1.用HQL查询出:(学生ID,学生名,学生年龄,学生卡号,号ID)
条件:①学生年龄在18-25间②学生卡号包含有’01’字符③以学生年龄降序排序及学生名升序排序

2.用HQL统计符号以上条件的学生的平均年龄。

二、提问原因:本来初学hql,不太会。烦请大佬指正。

@Test
public static List<list> findUserById(Integer id) {
        String hql ="SELECT s.id,s.name,s.age,c.cardNumber,c.id from Student s,StudentCard c where s.cid=c.id";
        if(s.age! = null && .equals(s.age)){
            hql += "and s.age between 18 and 25";
        }
        if(c.cardNumber! = null && .equals(c.cardNumber)){
            hql += "and c.cardNumber like '%01%'";
        }
        if(s.age! = null && s.name! = null){
            hql += "and order by s.age desc, s.name asc";
        }
        List<Student> list = session.createQuery(hql).list();
        for(Student student: list) {
            System.out.println(student);
        }
}
List results = session.find("select count(*), avg(s.age) from User as user");
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?