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

时间:2011-03-10 08:39:34

标签: 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 .............
  group by tb.aca_year
 ................

有什么建议吗?

最诚挚的问候,

1 个答案:

答案 0 :(得分:0)

您可以这样做:

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 ................