怎么把这两个sql语句整合到一起,这两套只有加粗那里不一样

SELECT he.name as 姓名

FROM OMS_OE_ORDER_TYPES_REPORT T 

,oms_oe_order_types tt,

hr_employee he,

sys_user su,

OMS_LO_REMAIN olr,

OMS_LO_RESPONSIBLE res

where  tt.order_type_id=t.order_type_id and t.order_type_id =olr.order_type_id 

--and tt.UNIT_ID=T.UNIT_ID

--and tt.CREATED_BY=res.CREATED_BY

--and su.CREATED_BY=res.CREATED_BY

and res.CREATED_BY=olr.CREATED_BY

and olr.created_by=su.employee_id

and  he.EMPLOYEE_ID=su.EMPLOYEE_ID

--and tt.LAST_UPDATED_BY=su.LAST_UPDATED_BY

--and su.LAST_UPDATED_BY=res.LAST_UPDATED_BY

--and res.LAST_UPDATED_BY=olr.LAST_UPDATED_BY

--and su.LAST_UPDATE_LOGIN=olr.LAST_UPDATE_LOGIN

and T.PA_UNIT_CODE=${tp}

AND tt.left_flag='Y'

and olr.status<>9

${if(len(BookDates)=0,"","and res.START_DATE>=to_date('"+BookDates+"','yyyy-mm-dd') and res.high_version='Y'")}

${if(len(BookDates)=0,"","and res.START_DATE<=to_date('"+BookDatee+"','yyyy-mm-dd')and res.high_version='Y'")}

${if(len(BookDates_c)=0,"","and res.PZ_DATE>=to_date('"+BookDates_c+"','yyyy-mm-dd')")}

${if(len(BookDates_c)=0,"","and res.PZ_DATE<=to_date('"+BookDatee_c+"','yyyy-mm-dd')")}

group by he.name

--------------------------------------------------------------------------------------------

SELECT count(olr.remain_no) as 差错

FROM OMS_OE_ORDER_TYPES_REPORT T 

,oms_oe_order_types tt,

hr_employee he,

sys_user su,

OMS_LO_REMAIN olr,

OMS_LO_RESPONSIBLE res

where  tt.order_type_id=t.order_type_id and t.order_type_id =olr.order_type_id 

and res.CREATED_BY=olr.CREATED_BY

and olr.created_by=su.employee_id

and  he.EMPLOYEE_ID=su.EMPLOYEE_ID

and T.PA_UNIT_CODE=${tp}

AND tt.left_flag='Y'

and olr.TYPES='遗留单' and olr.REMAIN_KIND=1

and olr.remain_no is not null

and olr.status<>9

${if(len(BookDates)=0,"","and res.START_DATE>=to_date('"+BookDates+"','yyyy-mm-dd') and res.high_version='Y'")}

${if(len(BookDates)=0,"","and res.START_DATE<=to_date('"+BookDatee+"','yyyy-mm-dd')and res.high_version='Y'")}

${if(len(BookDates_c)=0,"","and res.PZ_DATE>=to_date('"+BookDates_c+"','yyyy-mm-dd')")}

${if(len(BookDates_c)=0,"","and res.PZ_DATE<=to_date('"+BookDatee_c+"','yyyy-mm-dd')")}

FineReport 帆软用户XpbwOTiAvi 发布于 2022-6-7 16:18 (编辑于 2022-6-7 16:23)
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
0
CD20160914Lv8专家互助
发布于2022-6-7 16:19(编辑于 2022-6-7 16:26)

select 

t1.姓名,

t2.差错

from (

SELECT 

he.name as 姓名

FROM OMS_OE_ORDER_TYPES_REPORT T 

,oms_oe_order_types tt,

hr_employee he,

sys_user su,

OMS_LO_REMAIN olr,

OMS_LO_RESPONSIBLE res

where  tt.order_type_id=t.order_type_id and t.order_type_id =olr.order_type_id 

and res.CREATED_BY=olr.CREATED_BY

and olr.created_by=su.employee_id

and  he.EMPLOYEE_ID=su.EMPLOYEE_ID

and T.PA_UNIT_CODE=${tp}

AND tt.left_flag='Y'

and olr.status<>9

${if(len(BookDates)=0,"","and res.START_DATE>=to_date('"+BookDates+"','yyyy-mm-dd') and res.high_version='Y'")}

${if(len(BookDates)=0,"","and res.START_DATE<=to_date('"+BookDatee+"','yyyy-mm-dd')and res.high_version='Y'")}

${if(len(BookDates_c)=0,"","and res.PZ_DATE>=to_date('"+BookDates_c+"','yyyy-mm-dd')")}

${if(len(BookDates_c)=0,"","and res.PZ_DATE<=to_date('"+BookDatee_c+"','yyyy-mm-dd')")}

group by he.name

) t1

left join 

(

SELECT 

he.name,

count(olr.remain_no) as 差错

FROM OMS_OE_ORDER_TYPES_REPORT T 

,oms_oe_order_types tt,

hr_employee he,

sys_user su,

OMS_LO_REMAIN olr,

OMS_LO_RESPONSIBLE res

where  tt.order_type_id=t.order_type_id and t.order_type_id =olr.order_type_id 

and res.CREATED_BY=olr.CREATED_BY

and olr.created_by=su.employee_id

and  he.EMPLOYEE_ID=su.EMPLOYEE_ID

and T.PA_UNIT_CODE=${tp}

AND tt.left_flag='Y'

and olr.TYPES='遗留单' and olr.REMAIN_KIND=1

and olr.remain_no is not null

and olr.status<>9

${if(len(BookDates)=0,"","and res.START_DATE>=to_date('"+BookDates+"','yyyy-mm-dd') and res.high_version='Y'")}

${if(len(BookDates)=0,"","and res.START_DATE<=to_date('"+BookDatee+"','yyyy-mm-dd')and res.high_version='Y'")}

${if(len(BookDates_c)=0,"","and res.PZ_DATE>=to_date('"+BookDates_c+"','yyyy-mm-dd')")}

${if(len(BookDates_c)=0,"","and res.PZ_DATE<=to_date('"+BookDatee_c+"','yyyy-mm-dd')")}

group by he.name) t2

 on t1.name=t2.name

最佳回答
0
圣体叶小凡Lv6高级互助
发布于2022-12-18 15:13

再定义一个参数,把那边不一样的包括进去就行,根据你的条件看到底执不执行这个关联关系;

SELECT he.name as 姓名

FROM OMS_OE_ORDER_TYPES_REPORT T 

,oms_oe_order_types tt,

hr_employee he,

sys_user su,

OMS_LO_REMAIN olr,

OMS_LO_RESPONSIBLE res

where  tt.order_type_id=t.order_type_id and t.order_type_id =olr.order_type_id 

--and tt.UNIT_ID=T.UNIT_ID

--and tt.CREATED_BY=res.CREATED_BY

--and su.CREATED_BY=res.CREATED_BY

and res.CREATED_BY=olr.CREATED_BY

and olr.created_by=su.employee_id

and  he.EMPLOYEE_ID=su.EMPLOYEE_ID

--and tt.LAST_UPDATED_BY=su.LAST_UPDATED_BY

--and su.LAST_UPDATED_BY=res.LAST_UPDATED_BY

--and res.LAST_UPDATED_BY=olr.LAST_UPDATED_BY

--and su.LAST_UPDATE_LOGIN=olr.LAST_UPDATE_LOGIN

and T.PA_UNIT_CODE=${tp}

AND tt.left_flag='Y'

${if(len(canshu)=0,"","and olr.TYPES='遗留单' and olr.REMAIN_KIND=1

and olr.remain_no is not null")}

and olr.status<>9

${if(len(BookDates)=0,"","and res.START_DATE>=to_date('"+BookDates+"','yyyy-mm-dd') and res.high_version='Y'")}

${if(len(BookDatee)=0,"","and res.START_DATE<=to_date('"+BookDatee+"','yyyy-mm-dd')and res.high_version='Y'")}

${if(len(BookDates_c)=0,"","and res.PZ_DATE>=to_date('"+BookDates_c+"','yyyy-mm-dd')")}

${if(len(BookDatee_c)=0,"","and res.PZ_DATE<=to_date('"+BookDatee_c+"','yyyy-mm-dd')")}

group by he.name

  • 3关注人数
  • 389浏览人数
  • 最后回答于:2022-12-18 15:13
    请选择关闭问题的原因
    确定 取消
    返回顶部