2016-09-16 49 views
1
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; 

在此查询的SELECT COUNT它显示了一个运行时异常,因为查询不excecute为特定的列值

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

回答

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; 
相关问题