简体   繁体   English

CTE总数

[英]CTEs count and sum

I am trying to get the sum of the count I did on "cll.Claim_number" column.The below CTE is part of 3 othe CTEs and the CTEs run perfectly but now I want to only bring in the "sum" of "COUNTOFSERVICES" from the count I did on cll.Claim_number. 我正在尝试获取在“ cll.Claim_number”列上所做的计数总和。下面的CTE是3个CTE的一部分,并且CTE运行良好,但是现在我只想输入“ COUNTOFSERVICES”的“和”从我对cll.Claim_number所做的计数中。 I want the output field to have only the sum with the rest of the fields I call out that's it not the count. 我希望输出字段仅包含我调用的其余字段的总和,而不是计数。 Below is what I have but it gives both the count and sum in the output when I only want the sum . 下面是我所拥有的,但是当我只想要总和时,它在输出中同时提供了计数和总和。 Thanks 谢谢

Select 
cll.company_desc as state,
cll.line_of_business_desc as Lineofbus,
cll.product_desc as Product,
cll.paymentdate as YearMonth,
cll.typeofservice,
prt.prov_type_short_desc as ProviderSpecialty,
cll.whole_claim_status_desc as Outcome,
count(cll.Claim_number) as "COUNTOFSERVICES",
sum(cll.Claim_number) as total
from claims cll

left join dw.DIM_PROVIDER_TYPE prt -- bringing in provider spec from claim
on cll.prov_type_dim_id = prt.prov_type_dim_id

Where cll.uniquerow = '1'--dedupping


Group By 
cll.company_desc,
Cll.line_of_business_desc,
cll.product_desc,
cll.paymentdate,
--cll.memb_dim_id,
cll.typeofservice,
prt.prov_type_short_desc,
cll.whole_claim_status_desc,
cll.Claim_number

Thanks @jarlh 谢谢@jarlh

I removed the cll.claimnumber from Group and did the below and I got exactly what I was looking for . 我从Group中删除了cll.claimnumber并执行以下操作,我得到了我想要的东西。 I also removed the sum since the count did exactly what I wanted after removing the claimnumber from GROUP. 我也删除了总和,因为从GROUP删除索偿号后,计数完全符合我的要求。

Providers as (

Select 
cll.company_desc as state,
cll.line_of_business_desc as Lineofbus,
cll.product_desc as Product,
cll.paymentdate as YearMonth,
cll.typeofservice,
prt.prov_type_short_desc as ProviderSpecialty,
cll.whole_claim_status_desc as Outcome,
count(cll.Claim_number) as "COUNTOFSERVICES"
--sum(cll.Claim_number) as total --removed
from claims cll

left join dw.DIM_PROVIDER_TYPE prt -- bringing in provider spec from claim
on cll.prov_type_dim_id = prt.prov_type_dim_id

Where cll.uniquerow = '1'--dedupping


Group By 
cll.company_desc,
Cll.line_of_business_desc,
cll.product_desc,
cll.paymentdate,
--cll.memb_dim_id,
cll.typeofservice,
prt.prov_type_short_desc,
cll.whole_claim_status_desc



)  select * from providers

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM