休眠,如何根据条件进行计数 [英] Hibernate, how to count with condition
本文介绍了休眠,如何根据条件进行计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用oracle和hibernate进行映射.我想用count()函数中的条件来计数.我的代码是:
I am using oracle and hibernate for mapping. I want to count with a condition in count() function. my code is:
select count(case when st.averageMark < su.gradePass then 1 else 0 end)
from Study st join st.subject su
where st.acaYear in (2009)
and st.semester = 4
and su.idSeq = 1330
group by st.acaYear
代码什么也没给我.我使用sum而不是count来返回结果,但这是错误的,结果比我想象的要大.
the code return me nothing. I used sum instead of count it returned a result but it is wrong, the result is bigger than I suppose it to be.
先谢谢.
推荐答案
我刚刚使用以下代码解决了问题.
I just solved the problem with the following code.
select sum(case when st.averageMark >= su.gradePass then 1 else 0 end) as pass,
sum(case when st.averageMark < su.gradePass then 1 else 0 end) as fail
from Study st join st.subject su
where st.acaYear in (2009) and st.semester = 4 and su.idSeq = 1330
group by st.acaYear
这篇关于休眠,如何根据条件进行计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文