【发布时间】:2022-01-19 22:38:47
【问题描述】:
只有当“类型列”中的数据=总发生损失、多付损失、救助和代位求偿时,我才需要对“金额”列中的数据求和。你知道我可以在下面的代码中使用什么 if 语句来完成这个吗?
select total.*
from (
select p.policyNum,
p.stateID,
p.effectiveDate as date,
p.premiumTotal,
a.claimFreeDiscount,
a.homeownerDiscount,
a.policyZip,
mb.claimnumber,
**if .....**
sum(mb.amount) as totalclm
from aggressive.dbo.Policy as p
inner join Aggressive.dbo.Auto as a
on p.policyID = a.policyID
left join MicrosoftPowerBI.dbo.ClaimTransactionDetail as mb
on p.policyid = mb.policyid
where p.stateID = 74 and
p.companyID = 10 and
p.status =1
group by p.policynum,
p.stateID,
p.effectiveDate,
p.premiumTotal,
a.claimFreeDiscount,
a.homeownerDiscount,
a.policyZip,
mb.claimnumber)
as total
order by total.totalclm desc
【问题讨论】:
-
该代码看起来像 SQL - 请在您正在使用的数据库的问题中添加一个标签。
标签: sql if-statement sum