查询不会超出特定列值

时间:2016-09-16 06:58:49

标签: java mysql hibernate

select count(*) as allCount, sum(t.status='Approved') as approvedCount, sum(t.status='Overdue') as overdueCount, 
             sum(t.status='Rejected') as rejectedCount, sum(t.status='Awaiting Approval') as awaitingApprovalCount,
            sum(t.status='Not Submitted') as notSubmittedCount
            from timesheet as t where t.empl_id=2;

在此查询中,它将运行时异常显示为

org.hibernate.hql.internal.ast.querrySyntax.Exception:expecting CLOSE ,found "=" nearline 1,sum(t.status="Approved")

1 个答案:

答案 0 :(得分:0)

几乎尝试使用总和(

时的情况
select count(*) as allCount, 
sum(case when t.status='Approved' then 1 else 0 end) as approvedCount, 
sum(case when t.status='Overdue'  then 1 else 0 end) as overdueCount, 
sum(case when t.status='Rejected' then 1 else 0 end) as rejectedCount, 
sum(case when t.status='Awaiting Approval' then 1 else 0 end) as awaitingApprovalCount,
sum(case when t.status='Not Submitted' then 1 else 0 end) as notSubmittedCount
from timesheet as t where t.empl_id=2;