gpt4 book ai didi

java - 查询不会针对特定列值的选择计数执行

转载 作者:行者123 更新时间:2023-11-30 22:12:43 25 4
gpt4 key购买 nike

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.querySyntax.Exception:expecting CLOSE ,found "=" nearline 1,sum(t.status="Approved")

最佳答案

几乎有尝试使用 sum (case when

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;

关于java - 查询不会针对特定列值的选择计数执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39525480/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com