- 当代码集2正常运行时,下面的代码集1失败。两组SQL语法之间的唯一区别是a.struct_doc_id = 13685的附加条件放在子查询中以创建“GetAllSubTypes”。附加条件是“和a.struct_doc_id = 13685”的限制器。我在代码集1中得到的错误是“ORA-01427:单行子查询返回多行01427. 00000 - ”单行子查询返回多行。有人可以帮忙吗?
-- Both Code Sets 1 and Code Set 2 are below each other
-- CODE SET 1
with max_amend
as
(
select STRUCT_DOC_id, max(amendment_number) max_amend from MN_STRUCTURED_CONTRACT
group by STRUCT_DOC_id
),
Extensions
as
(
select struct_doc_id, count(*) - 1 Num_Extensions
from
(
select distinct struct_doc_id, end_date from MN_STRUCTURED_doc_ver
)
group by struct_doc_id
),
Distributors
as
(
select A.CONTRACT_ID,A.CONTRACT_ref_num,A.BA_INT_ID,LISTAGG(B.WHOLE_NAME,' | ') WITHIN GROUP (ORDER BY A.CONTRACT_ID DESC) Distributors
from MN_BA_INT A, MN_BA_INT_WHOLE B, MN_STRUCTURED_DOC C
where
A.CONTRACT_ID=C.struct_doc_id
AND A.BA_INT_ID=B.BA_INT_ID
--and struct_doc_id=13603
--and struct_doc_id=13685
group by A.CONTRACT_ID,A.CONTRACT_ref_num,A.BA_INT_ID
),
prev_cont_Id
as
(
select a.struct_doc_id,b.alternate_id PREV_CONT_ID from
(
select a.STRUCT_DOC_id, a.amendment_number, max(a.ver_num) max_ver from mn_structured_contract_ver a group by a.STRUCT_DOC_id,a.amendment_number
) a,
(
select a.STRUCT_DOC_id, a.alternate_id, a.amendment_number,a.ver_num from mn_structured_contract_ver a
) b,
max_amend c
-- section
WHERE
a.STRUCT_DOC_id=b.STRUCT_DOC_id and a.max_ver=b.ver_num and a.amendment_number=c.max_amend-1 and c.STRUCT_DOC_id=a.STRUCT_DOC_id
),
Contract_Orig
as
(
select a.STRUCT_DOC_ID, a.start_date, a.end_date from MN_STRUCTURED_doc_ver a,
(
select STRUCT_DOC_ID, MIN(VER_NUM) VER_NUM from MN_STRUCTURED_CONTRACT_VER
WHERE AMENDMENT_NUMBER=0 AND CTRT_DOC_STATUS='Off.IMPL'
GROUP BY STRUCT_DOC_ID
) b
where a.STRUCT_DOC_ID=b.STRUCT_DOC_ID
and a.VER_NUM=b.VER_NUM
order by struct_doc_id
),
PriceP
as
(
select calc_obj_id,max(cf_prc_strategy_report_id) cf_prc_strategy_report_id from MN_CF_PRC_STRATEGY_REPORT
group by calc_obj_id
),
Component
as
(
select calc_obj_id,max(cf_prc_component_report_id) cf_prc_component_report_id from MN_CF_PRC_COMPONENT_REPORT
where type like '%Basis%'
group by calc_obj_id
),
GetAllSubTypes
as
(
select distinct a.STRUCT_DOC_id,
l.strategy_id,
d.display_name PP_Sub_Type,
l.min_value
FROM
mn_structured_contract a,MN_DYN_ENUM_CONST d,max_amend e,
MN_CF_PRC_COMPONENT_REPORT L, Component M, MN_PRICE_MASTER_LI b
WHERE
e.max_amend=b.amendment_number
and m.cf_prc_component_report_id=l.cf_prc_component_report_id
and l.strategy_id=b.CF_STRATEGY_ID
and b.OVERRIDE_PRICE_RANK=d.code
and a.STRUCT_DOC_id=b.STRUCT_DOC_id
and m.cf_prc_component_report_id=l.cf_prc_component_report_id
and a.STRUCT_DOC_id=e.STRUCT_DOC_id
and d.ns_id in ('734')
-- WHEN THIS CONDITION BELOW IS REMOVED THE SQL FAILS
--and a.struct_doc_id=13685
),
ListSubs
as
(
SELECT STRUCT_DOC_id Contract_ID,LISTAGG(PP_Sub_Type, ' | ') WITHIN GROUP (ORDER BY STRUCT_DOC_id DESC) Contract
FROM GetAllSubTypes
group by STRUCT_DOC_id
),
GetAggCommitt
as
(
select STRUCT_DOC_id, sum(min_value) All_Value from GetAllSubTypes
group by STRUCT_DOC_id
),
GetIndivCommitt
as
(
select STRUCT_DOC_id, PP_Sub_Type, min_value from GetAllSubTypes
),
GetPercentCommitt
as
(
select a.STRUCT_DOC_id, a.PP_Sub_Type, a.min_value Commitment_Val, round(a.min_value/b.all_value,2) Percent_Total from GetIndivCommitt a, GetAggCommitt b
where a.STRUCT_DOC_id=b.STRUCT_DOC_id
),
Inclusions
as
(
select Contract_ID,
case when Contract='Yes' then 'No SubType' else Contract end PP_SUBTYPES,
case when upper(Contract) like '%WOUND%' then 'TRUE' else 'FALSE' end Wound_Included,
case when upper(Contract) like '%OSTOMY%' then 'TRUE' else 'FALSE' end Ostomy_Included,
case when upper(Contract) like '%SKIN%' then 'TRUE' else 'FALSE' end Skin_Included,
case when upper(Contract) like '%CONTINENCE%' then 'TRUE' else 'FALSE' end Continence_Included,
case when Contract like '%Mens Health%' then 'TRUE' else 'FALSE' end Mens_Included,
case when Contract like '%Womens%' then 'TRUE' else 'FALSE' end Womens_Included,
case when upper(Contract) like '%Endourology%' then 'TRUE' else 'FALSE' end EndoUrology_Included,
case when upper(Contract) like '%GPO%' then 'TRUE' else 'FALSE' end GPO_Included,
case when upper(Contract) like '%UC%' then 'TRUE' else 'FALSE' end UC_Included,
case when upper(Contract) like '%CHRONIC%' then 'TRUE' else 'FALSE' end Chronic_Included,
case when upper(Contract) like '%WSC%' then 'TRUE' else 'FALSE' end WSC_Included
from listsubs
)
select distinct
a.STRUCT_DOC_id,
e.max_amend,
h.member_name Analyst,
h.member_id,
Contract.member_name Customer,
a.ctrt_doc_status Contract_Status,
c.display_name Contract_Type,
a.alternate_id Contract_Number,
prev_cont_id.prev_cont_id Previous_Contract_Number,
Distributors.Distributors,
trunc(dates.start_date) Contract_Start_date,
trunc(Contract_Orig.end_date) Original_End_Date,
trunc(dates.end_date)Contract_End_Date,
mn_Address.Description Customer_Contact_Name,
mn_Address.Line1 Customer_Address,
MN_ADDRESS.CITY Customer_City,
MN_ADDRESS.STATE_PROV Customer_State,
MN_ADDRESS.POSTAL_ZIP Customer_Zip,
Extensions.Num_Extensions,
a.cust_ctrt_id_num,
q.All_Value Total_Commitment,
--Inclusions.PP_SUBTYPES,
Inclusions.Wound_Included,
Inclusions.Ostomy_Included,
Inclusions.Skin_Included,
Inclusions.Continence_Included,
Inclusions.Mens_Included,
Inclusions.Womens_Included,
Inclusions.EndoUrology_Included,
Inclusions.GPO_Included,
Inclusions.UC_Included,
Inclusions.Chronic_Included,
Inclusions.WSC_Included,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Wound%') else '0' end Wound_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Ostomy%') else '0' end Ostomy_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Skin%') else '0' end Skin_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Continence%') else '0' end Continence_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Mens%') else '0' end Mens_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Womens%') else '0' end Womens_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%EndoUrology%') else '0' end EndoUrology_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%GPO%') else '0' end GPO_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%UC%') else '0' end UC_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Chronic%') else '0' end Chronic_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%WSC%') else '0' end WSC_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Wound%') else 0 end Wound_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Ostomy%') else 0 end Ostomy_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Skin%') else 0 end Skin_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Continence%') else 0 end Continence_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Mens%') else 0 end Mens_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Womens%') else 0 end Womens_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%EndoUrology%') else 0 end EndoUrology_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%GPO%') else 0 end GPO_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%UC%') else 0 end UC_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Chronic%') else 0 end Chronic_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%WSC%') else 0 end WSC_Percentage
FROM
MN_PRICE_MASTER_LI b, MN_DYN_ENUM_CONST c, MN_DYN_ENUM_CONST d, max_amend e,
MN_CF_PRC_STRATEGY_REPORT f, PriceP g, mn_member h, MN_CF_PRC_COMPONENT_REPORT L, Component M, Inclusions, GetAggCommitt Q,
mn_member contract, mn_structured_doc dates, Contract_Orig, mn_Address, prev_cont_id, Extensions, mn_structured_contract a left join Distributors
on Distributors.CONTRACT_ID=a.STRUCT_DOC_id
WHERE b.OVERRIDE_PRICE_RANK IS NOT NULL
and c.code=a.ctrt_sub_type
and b.OVERRIDE_PRICE_RANK=d.code
and a.STRUCT_DOC_id=b.STRUCT_DOC_id
and a.STRUCT_DOC_id=dates.STRUCT_DOC_id
and a.STRUCT_DOC_id=q.STRUCT_DOC_id
and m.cf_prc_component_report_id=l.cf_prc_component_report_id
and c.ns_id in ('714')
and d.ns_id in ('734')
and e.max_amend=b.amendment_number
and a.STRUCT_DOC_id=e.STRUCT_DOC_id
and l.strategy_id=b.CF_STRATEGY_ID
and g.calc_obj_id=f.calc_obj_id
and g.cf_prc_strategy_report_id=f.cf_prc_strategy_report_id
and h.member_id=a.member_id_author
and contract.member_id=a.member_id_cust
and f.src_id=l.strategy_id
and mn_Address.member_id=a.member_id_cust
and mn_Address.usage_cde=8
and prev_cont_id.STRUCT_DOC_id=a.STRUCT_DOC_id
and Contract_Orig.STRUCT_DOC_ID=a.STRUCT_DOC_id
and Extensions.STRUCT_DOC_ID=a.STRUCT_DOC_id
--CODE SET 2
with max_amend
as
(
select STRUCT_DOC_id, max(amendment_number) max_amend from MN_STRUCTURED_CONTRACT
group by STRUCT_DOC_id
),
Extensions
as
(
select struct_doc_id, count(*) - 1 Num_Extensions
from
(
select distinct struct_doc_id, end_date from MN_STRUCTURED_doc_ver
)
group by struct_doc_id
),
Distributors
as
(
select A.CONTRACT_ID,A.CONTRACT_ref_num,A.BA_INT_ID,LISTAGG(B.WHOLE_NAME,' | ') WITHIN GROUP (ORDER BY A.CONTRACT_ID DESC) Distributors
from MN_BA_INT A, MN_BA_INT_WHOLE B, MN_STRUCTURED_DOC C
where
A.CONTRACT_ID=C.struct_doc_id
AND A.BA_INT_ID=B.BA_INT_ID
--and struct_doc_id=13603
--and struct_doc_id=13685
group by A.CONTRACT_ID,A.CONTRACT_ref_num,A.BA_INT_ID
),
prev_cont_Id
as
(
select a.struct_doc_id,b.alternate_id PREV_CONT_ID from
(
select a.STRUCT_DOC_id, a.amendment_number, max(a.ver_num) max_ver from mn_structured_contract_ver a group by a.STRUCT_DOC_id,a.amendment_number
) a,
(
select a.STRUCT_DOC_id, a.alternate_id, a.amendment_number,a.ver_num from mn_structured_contract_ver a
) b,
max_amend c
WHERE
a.STRUCT_DOC_id=b.STRUCT_DOC_id and a.max_ver=b.ver_num and a.amendment_number=c.max_amend-1 and c.STRUCT_DOC_id=a.STRUCT_DOC_id
),
Contract_Orig
as
(
select a.STRUCT_DOC_ID, a.start_date, a.end_date from MN_STRUCTURED_doc_ver a,
(
select STRUCT_DOC_ID, MIN(VER_NUM) VER_NUM from MN_STRUCTURED_CONTRACT_VER
WHERE AMENDMENT_NUMBER=0 AND CTRT_DOC_STATUS='Off.IMPL'
GROUP BY STRUCT_DOC_ID
) b
where a.STRUCT_DOC_ID=b.STRUCT_DOC_ID
and a.VER_NUM=b.VER_NUM
order by struct_doc_id
),
PriceP
as
(
select calc_obj_id,max(cf_prc_strategy_report_id) cf_prc_strategy_report_id from MN_CF_PRC_STRATEGY_REPORT
group by calc_obj_id
),
Component
as
(
select calc_obj_id,max(cf_prc_component_report_id) cf_prc_component_report_id from MN_CF_PRC_COMPONENT_REPORT
where type like '%Basis%'
group by calc_obj_id
),
GetAllSubTypes
as
(
select distinct a.STRUCT_DOC_id,
l.strategy_id,
d.display_name PP_Sub_Type,
l.min_value
FROM
mn_structured_contract a,MN_DYN_ENUM_CONST d,max_amend e,
MN_CF_PRC_COMPONENT_REPORT L, Component M, MN_PRICE_MASTER_LI b
WHERE
e.max_amend=b.amendment_number
and m.cf_prc_component_report_id=l.cf_prc_component_report_id
and l.strategy_id=b.CF_STRATEGY_ID
and b.OVERRIDE_PRICE_RANK=d.code
and a.STRUCT_DOC_id=b.STRUCT_DOC_id
and m.cf_prc_component_report_id=l.cf_prc_component_report_id
and a.STRUCT_DOC_id=e.STRUCT_DOC_id
and d.ns_id in ('734')
-- WHEN THIS CONDITION BELOW IS REMOVED THE SQL FAILS
and a.struct_doc_id=13685
),
ListSubs
as
(
SELECT STRUCT_DOC_id Contract_ID,LISTAGG(PP_Sub_Type, ' | ') WITHIN GROUP (ORDER BY STRUCT_DOC_id DESC) Contract
FROM GetAllSubTypes
group by STRUCT_DOC_id
),
GetAggCommitt
as
(
select STRUCT_DOC_id, sum(min_value) All_Value from GetAllSubTypes
group by STRUCT_DOC_id
),
GetIndivCommitt
as
(
select STRUCT_DOC_id, PP_Sub_Type, min_value from GetAllSubTypes
),
GetPercentCommitt
as
(
select a.STRUCT_DOC_id, a.PP_Sub_Type, a.min_value Commitment_Val, round(a.min_value/b.all_value,2) Percent_Total from GetIndivCommitt a, GetAggCommitt b
where a.STRUCT_DOC_id=b.STRUCT_DOC_id
),
Inclusions
as
(
select Contract_ID,
case when Contract='Yes' then 'No SubType' else Contract end PP_SUBTYPES,
case when upper(Contract) like '%WOUND%' then 'TRUE' else 'FALSE' end Wound_Included,
case when upper(Contract) like '%OSTOMY%' then 'TRUE' else 'FALSE' end Ostomy_Included,
case when upper(Contract) like '%SKIN%' then 'TRUE' else 'FALSE' end Skin_Included,
case when upper(Contract) like '%CONTINENCE%' then 'TRUE' else 'FALSE' end Continence_Included,
case when Contract like '%Mens Health%' then 'TRUE' else 'FALSE' end Mens_Included,
case when Contract like '%Womens%' then 'TRUE' else 'FALSE' end Womens_Included,
case when upper(Contract) like '%Endourology%' then 'TRUE' else 'FALSE' end EndoUrology_Included,
case when upper(Contract) like '%GPO%' then 'TRUE' else 'FALSE' end GPO_Included,
case when upper(Contract) like '%UC%' then 'TRUE' else 'FALSE' end UC_Included,
case when upper(Contract) like '%CHRONIC%' then 'TRUE' else 'FALSE' end Chronic_Included,
case when upper(Contract) like '%WSC%' then 'TRUE' else 'FALSE' end WSC_Included
from listsubs
)
select distinct
a.STRUCT_DOC_id,
e.max_amend,
h.member_name Analyst,
h.member_id,
Contract.member_name Customer,
a.ctrt_doc_status Contract_Status,
c.display_name Contract_Type,
a.alternate_id Contract_Number,
prev_cont_id.prev_cont_id Previous_Contract_Number,
Distributors.Distributors,
trunc(dates.start_date) Contract_Start_date,
trunc(Contract_Orig.end_date) Original_End_Date,
trunc(dates.end_date)Contract_End_Date,
mn_Address.Description Customer_Contact_Name,
mn_Address.Line1 Customer_Address,
MN_ADDRESS.CITY Customer_City,
MN_ADDRESS.STATE_PROV Customer_State,
MN_ADDRESS.POSTAL_ZIP Customer_Zip,
Extensions.Num_Extensions,
a.cust_ctrt_id_num,
q.All_Value Total_Commitment,
--Inclusions.PP_SUBTYPES,
Inclusions.Wound_Included,
Inclusions.Ostomy_Included,
Inclusions.Skin_Included,
Inclusions.Continence_Included,
Inclusions.Mens_Included,
Inclusions.Womens_Included,
Inclusions.EndoUrology_Included,
Inclusions.GPO_Included,
Inclusions.UC_Included,
Inclusions.Chronic_Included,
Inclusions.WSC_Included,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Wound%') else '0' end Wound_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Ostomy%') else '0' end Ostomy_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Skin%') else '0' end Skin_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Continence%') else '0' end Continence_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Mens%') else '0' end Mens_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Womens%') else '0' end Womens_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%EndoUrology%') else '0' end EndoUrology_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%GPO%') else '0' end GPO_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%UC%') else '0' end UC_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Chronic%') else '0' end Chronic_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%WSC%') else '0' end WSC_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Wound%') else 0 end Wound_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Ostomy%') else 0 end Ostomy_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Skin%') else 0 end Skin_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Continence%') else 0 end Continence_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Mens%') else 0 end Mens_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Womens%') else 0 end Womens_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%EndoUrology%') else 0 end EndoUrology_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%GPO%') else 0 end GPO_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%UC%') else 0 end UC_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Chronic%') else 0 end Chronic_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%WSC%') else 0 end WSC_Percentage
FROM
MN_PRICE_MASTER_LI b, MN_DYN_ENUM_CONST c, MN_DYN_ENUM_CONST d, max_amend e,
MN_CF_PRC_STRATEGY_REPORT f, PriceP g, mn_member h, MN_CF_PRC_COMPONENT_REPORT L, Component M, Inclusions, GetAggCommitt Q,
mn_member contract, mn_structured_doc dates, Contract_Orig, mn_Address, prev_cont_id, Extensions, mn_structured_contract a left join Distributors
on Distributors.CONTRACT_ID=a.STRUCT_DOC_id
WHERE b.OVERRIDE_PRICE_RANK IS NOT NULL
and c.code=a.ctrt_sub_type
and b.OVERRIDE_PRICE_RANK=d.code
and a.STRUCT_DOC_id=b.STRUCT_DOC_id
and a.STRUCT_DOC_id=dates.STRUCT_DOC_id
and a.STRUCT_DOC_id=q.STRUCT_DOC_id
and m.cf_prc_component_report_id=l.cf_prc_component_report_id
and c.ns_id in ('714')
and d.ns_id in ('734')
and e.max_amend=b.amendment_number
and a.STRUCT_DOC_id=e.STRUCT_DOC_id
and l.strategy_id=b.CF_STRATEGY_ID
and g.calc_obj_id=f.calc_obj_id
and g.cf_prc_strategy_report_id=f.cf_prc_strategy_report_id
and h.member_id=a.member_id_author
and contract.member_id=a.member_id_cust
and f.src_id=l.strategy_id
and mn_Address.member_id=a.member_id_cust
and mn_Address.usage_cde=8
and prev_cont_id.STRUCT_DOC_id=a.STRUCT_DOC_id
and Contract_Orig.STRUCT_DOC_ID=a.STRUCT_DOC_id
and Extensions.STRUCT_DOC_ID=a.STRUCT_DOC_id
答案 0 :(得分:0)
您在代码集1中注释掉的行会导致名为GetAllSubTypes的公用表表达式返回单行。如果没有它,这个公共表表达式会返回多行,考虑到以后如何使用这些行,会产生一个子查询,该子查询返回单行以最终返回多行。我还没有进行详尽的分析,因为我无法访问您的数据库,但似乎受影响的代码在case语句中:
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Wound%') else '0' end Wound_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Ostomy%') else '0' end Ostomy_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Skin%') else '0' end Skin_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Continence%') else '0' end Continence_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Mens%') else '0' end Mens_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Womens%') else '0' end Womens_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%EndoUrology%') else '0' end EndoUrology_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%GPO%') else '0' end GPO_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%UC%') else '0' end UC_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Chronic%') else '0' end Chronic_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select min_value from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%WSC%') else '0' end WSC_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Wound%') else 0 end Wound_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Ostomy%') else 0 end Ostomy_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Skin%') else 0 end Skin_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Continence%') else 0 end Continence_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Mens%') else 0 end Mens_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Womens%') else 0 end Womens_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%EndoUrology%') else 0 end EndoUrology_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%GPO%') else 0 end GPO_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%UC%') else 0 end UC_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Chronic%') else 0 end Chronic_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select Percent_Total from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%WSC%') else 0 end WSC_Percentage
例如,上面的GetIndivCommitt
是从GetAllSubTypes
中提取数据的另一个常用表表达式。它在上面的CASE语句中使用的方式,SELECT GetIndivCommitt
必须返回单行,否则语句将失败,因为您已经注意到了。您可以通过更改CASE语句中的SELECT来使用限制SELECT返回单个值的函数来修补它。在下面的示例中,我已将LEAST
函数添加到每个语句中 - 根据您的代码,我不知道这是否真的是正确的,但它的目的是作为示例:
case when Inclusions.Wound_Included = 'TRUE' then (select LEAST(min_value) from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Wound%') else '0' end Wound_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select LEAST(min_value) from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Ostomy%') else '0' end Ostomy_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select LEAST(min_value) from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Skin%') else '0' end Skin_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select LEAST(min_value) from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Continence%') else '0' end Continence_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select LEAST(min_value) from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Mens%') else '0' end Mens_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select LEAST(min_value) from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Womens%') else '0' end Womens_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select LEAST(min_value) from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%EndoUrology%') else '0' end EndoUrology_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select LEAST(min_value) from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%GPO%') else '0' end GPO_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select LEAST(min_value) from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%UC%') else '0' end UC_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select LEAST(min_value) from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Chronic%') else '0' end Chronic_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select LEAST(min_value) from GetIndivCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%WSC%') else '0' end WSC_Commit,
case when Inclusions.Wound_Included = 'TRUE' then (select LEAST(Percent_Total) from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Wound%') else 0 end Wound_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select LEAST(Percent_Total) from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Ostomy%') else 0 end Ostomy_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select LEAST(Percent_Total) from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Skin%') else 0 end Skin_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select LEAST(Percent_Total) from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Continence%') else 0 end Continence_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select LEAST(Percent_Total) from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Mens%') else 0 end Mens_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select LEAST(Percent_Total) from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Womens%') else 0 end Womens_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select LEAST(Percent_Total) from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%EndoUrology%') else 0 end EndoUrology_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select LEAST(Percent_Total) from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%GPO%') else 0 end GPO_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select LEAST(Percent_Total) from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%UC%') else 0 end UC_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select LEAST(Percent_Total) from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%Chronic%') else 0 end Chronic_Percentage,
case when Inclusions.Wound_Included = 'TRUE' then (select LEAST(Percent_Total) from GetPercentCommitt b, mn_structured_contract a
where b.STRUCT_DOC_id=a.STRUCT_DOC_id and b.PP_Sub_Type like '%WSC%') else 0 end WSC_Percentage
以上是作为一个例子。您可以自行决定是否对您的使用有效,并进行任何必要的更改以将代码转换为您需要它执行的任何操作。
祝你好运。