开发者

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

开发者 https://www.devze.com 2023-02-16 10:47 出处:网络
I have a problem writing HQL. The problem is that I want something like this to be transferred to HQL select

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

精彩评论

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