hql语句
select attendUserName,sum(case when attendTypeId = '1' then 1 else 0 end) [迟到],sum(case when attendTypeId = '2' then 1 else 0 end) [缺勤],sum(case when attendTypeId = '3' then 1 else 0 end) [早退]  from AttendanceManageEntity group by attendUserName而我的AttendanceManageEntity实体对象只有attendUserName,没有早退,迟到,缺勤这些对象,所以结果集只有attendUserName的结果。
请问如果查询到我需要的结果集里有:
attendUserName,迟到,缺勤,早退

解决方案 »

  1.   

    AttendanceManageEntity对象中肯定有attendTypeId 属性吧case when明白啥意思吧。
      

  2.   

    写成存储过程。或者直接用sql。并不是说用了hibernate就一定得写HQL。也并不是说HQL永远都是最好的
      

  3.   

    这时候你查询出来的是个Object[]数组的集合 ,数组的元素一次对应你要查询的值 
      

  4.   

    我要的结果是
    attendUserName   早退   迟到     缺勤
            甲           1     5       0
           乙           3     1       2
    而现在查到的只有
    attendUserName   
            甲          
           乙           
      

  5.   

    select attendUserName,sum(case when attendTypeId = '1' then 1 else 0 end) as late,sum(case when attendTypeId = '2' then 1 else 0 end) as absence,sum(case when attendTypeId = '3' then 1 else 0 end) as early from AttendanceManageEntity group by attendUserName
     没测试过 如果你sum 没问题的话应该可以!!  只是取 别名而已