开发者

How to count 2 fields with different conditions for each count in HQL

I have a problem writing HQL. The problem is that I want something like this to be transferred to 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
 ................

any suggestion please?

Best Regards,


You can do something like this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜