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");