CTE计数和总和

时间:2018-04-09 20:31:32

标签: sql oracle count sum

我试图获得我在“cll.Claim_number”列上所做的计数总和。下面的CTE是其他CTE的一部分,CTE运行完美,但现在我只想带来“总和” “COUNTOFSERVICES”来自我在cll.Claim_number上的计数。我希望输出字段只有我调用的其余字段的总和,这不是计数。下面是我的内容,但是当我只想要总和时,它给出了输出中的计数和总和。感谢

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

1 个答案:

答案 0 :(得分:0)

谢谢@jarlh

我从Group中删除了cll.claimnumber并执行了以下操作,我得到了我正在寻找的内容。我也删除了总和,因为在从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