Database 如何为HQL中的每个计数计数计数2个具有不同条件的字段

Database 如何为HQL中的每个计数计数计数2个具有不同条件的字段,database,hibernate,hql,Database,Hibernate,Hql,我在编写HQL时遇到问题。 问题是,我希望这样的东西被传输到HQL select tb.aca_year, (case when tw.isfulltime = 1 then count(te) end) as fulltime, (case when tw.isfulltime = 0 then count(te) end) as parttime from timetable tb, teacher te, teacherworktype tw where .

我在编写HQL时遇到问题。 问题是,我希望这样的东西被传输到HQL

 select 
   tb.aca_year, 
   (case when tw.isfulltime = 1 then count(te) end) as fulltime,
   (case when tw.isfulltime = 0 then count(te) end) as parttime
 from timetable tb, teacher te, teacherworktype tw 
  where .............
  group by tb.aca_year
 ................
有什么建议吗


致以最诚挚的问候,

您可以这样做:

select tb.aca_year, 
    sum(case when tw.isfulltime = 1 then 1 else 0 end) as fulltime, 
    sum(case when tw.isfulltime = 0 then 1 else 0 end) as parttime
from timetable tb, teacher te, teacherworktype tw 
where ............. 
group by tb.aca_year ................

如果不知道类模型,就不能编写HQL。所以,告诉我们一些关于你们的课程……谢谢你们关心我的问题。然而,这些课程很长。你能根据我的问题来帮我吗?我很困惑。当tw.isfulltime既不在聚合函数中,也不在GROUPBY子句中时,它如何实际工作?