Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate HQL最小最大值,如何_Hibernate_Hql - Fatal编程技术网

Hibernate HQL最小最大值,如何

Hibernate HQL最小最大值,如何,hibernate,hql,Hibernate,Hql,我有两个目标:“母亲”和“孩子”。 母亲有很多孩子, 我怎样才能从DB那里得到一个只有两个孩子(或更少)的母亲,一个小一点,一个大一点。 谢谢 编辑: 我想要的母亲有很多孩子,但我只想要越小越好 诸如此类: 从母亲m离开,加入孩子c 其中(max(c.age)或min(c.age))来自母亲m,其中count(m.Children)我找到了这个,它可以工作: from M as m left join m.C as c where m.Id = :idM and (c.Age = (se

我有两个目标:“母亲”和“孩子”。 母亲有很多孩子, 我怎样才能从DB那里得到一个只有两个孩子(或更少)的母亲,一个小一点,一个大一点。 谢谢

编辑:

我想要的母亲有很多孩子,但我只想要越小越好

诸如此类:

从母亲m离开,加入孩子c
其中(max(c.age)或min(c.age))

来自母亲m,其中count(m.Children)我找到了这个,它可以工作:

from M as m    
left join m.C as c
where m.Id = :idM
and
(c.Age = (select min(c.Age) from C c where c.M.Id = :idM)
or
c.Age = (select max(c.Age) from C c where c.M.Id = :idM))
order by c.Age
from M as m    
left join m.C as c
where m.Id = :idM
and
(c.Age = (select min(c.Age) from C c where c.M.Id = :idM)
or
c.Age = (select max(c.Age) from C c where c.M.Id = :idM))
order by c.Age