Oracle SQL nvl(),listagg() within group(),TO_CHAR(),CASE WHEN THEN ELSE END

本文详细介绍了Oracle SQL中的几个关键函数:NVL用于处理NULL值,例如将NULL替换为指定值;LISTAGG用于合并相同条件的列值,并按照指定顺序显示;TO_CHAR用于日期格式转换;CASE WHEN THEN ELSE END提供了类似IF的逻辑判断功能,根据条件决定返回哪个值。

Oracle SQL 函数使用记录

nvl(列名,替换值)

NVL(column_name,0) 用来判断字段的值是否为null,如果查询的字段值为null,则将其用其他字符代替,效果如下
在这里插入图片描述
在这里插入图片描述

listagg(要合并的列名,分隔符) within group(order by 排序列名 ASC/DESC )

LISTAGG(ENAME, ‘,’) WITHIN GROUP (ORDER BY ENAME)用来合并条件相同的字段值,结果用1行显示,效果如下
在这里插入图片描述
在这里插入图片描述

TO_CHAR(HIREDATE,‘YYYY-MM-DD’)

TO_CHAR()用来转换格式,我这里用来转换日期格式,其他用处暂时不知,效果如下
在这里插入图片描述

CASE WHEN THEN ELSE END

个人觉得是SQL中的if语句吧,效果如下
在这里插入图片描述
根据列JOB为判断条件,满足条件给新列NEW_JOB插入 THEN后面的值,不满足则插入 ELSE后面的值。

这个是原本的sql,用了很多方法,DBMS_LOB.SUBSTR,COALESCE都试了,还是没有效果 with mps_info as ( select distinct nvl(a.productfamily, b.productfamily) productfamily, nvl(a.timename, b.mfgmonth) mfgmonth, nvl( b.mps_modify , a.STRETCHTARGET) mps_modify from ( select prodtype||'-'||category productfamily, timename , STRETCHTARGET from P_MFG_CREATE.rpt_tgv_kpi_spec where kpiname ='InPut' and timetype = 'M' and kpitype ='Prod' and fabsite ='Overall' and timename ='2025-M09' ) a full join (select * from P_MFG_CREATE.RPT_TGT_RAP_MPSINPUT_CONFIG where 1=1 and mfgmonth ='2025-M09' ) b on a.productfamily = b.productfamily and a.timename = b.mfgmonth ), basic_info as ( select groupname , recipe_group , recipe , productfamily , requiredcapability capability, p_mfg_create.fun_LISTAGGPURE(listagg(stagename ,',') within group(order by stagename)) as stagename , avG(tgtuptime) tgtuptime , avg(tgtme) tgtme , avg(wph) wph , SUM(STEP_CNT) STEP_CNT from ( select distinct groupname ,recipe_group , recipe , productfamily , requiredcapability , stagename ,tgtuptime ,tgtme ,wph , STEP_CNT from p_MFG_create.RPT_ODST_PRDRAP_STATICSTATE where 1=1 and productname in ('Y006C','Y013D','Y046D','Y047C','Y047D','Y065B','Y065C','Y067A','Y068C','Y070C','Y085B','Y087F','Y088F','Y095B','Y095D','Y096B','Y096C','Y096D','Y097F','Y097G','Y098C','Y098D','Y125B','Y126B','Y127D','Y127E','Y128A','Y128B','Y128C','Y130C','Y148A','Y175B','Y176C','Y177A','Y177B','Y178B','Y178C','Y186E','Y188A','Y188B','Y188D','Y188F','Y195B','Y196C','Y196E','Y196G','Y197B','Y198C','Y198D','Y198F','Y198G','Y198H','Y800HM01') and groupname in ('BE TEOS') and groupname !='OTHER') a group by groupname ,recipe_group , recipe , productfamily , requiredcapability ), non_key_eqp as ( select eqpid from P_MFG_CREATE.RPT_TGT_GROUP_EQP e join P_MFG_CREATE.RPT_TGT_GROUP_RULE g on e.group_key = g.group_key where 1=1 and e.enable='Y' AND e.FLAG='Y' and e.category='Special' and instr(e.eqpid,'_')>0 and g.group_name not in ('BE TEOS') ), tmp_eqp_list as ( select distinct a.eqpid , b.full_config from ( select eqpid from P_MFG_CREATE.RPT_TGT_GROUP_EQP e join P_MFG_CREATE.RPT_TGT_GROUP_RULE g on e.group_key = g.group_key where 1=1 and e.enable='Y' AND e.FLAG='Y' and group_name in ('BE TEOS') union select eqpid from P_MFG_CREATE.RPT_TGT_RAP_STATICSTATE_CONFIG where category ='eqpid' and mfgmonth ='2025-M09' and eqpgroup in ('BE TEOS') union select eqpid from p_MFG_create.RPT_ODST_PRDRAP_PPID_CHK where recipelist in (select recipe from basic_info) ) a left join ( select DISTINCT eqpid,PROCUNITCOUNT/decode(TAKTTIMESTARTCHAMBERLIKE,0,'',TAKTTIMESTARTCHAMBERLIKE) full_config from P_MFG_CREATE.RPT_TGT_WPH_EQP_CONFIG WHERE EQPID !='Dummy' ) b on substr(a.eqpid,1,instr(a.eqpid,'_')-1) = b.eqpid ), --剔除non key chamber eqp_list as ( select t.* from tmp_eqp_list t left join non_key_eqp n on t.eqpid = n.eqpid where n.eqpid is null ), eqp_flag as ( select * from P_MFG_CREATE.RPT_TGT_RAP_STATICSTATE_CONFIG where category ='eqpid' and mfgmonth ='2025-M09' and eqpgroup in ('BE TEOS') ), --每个机台的ppid状态、填写的plan release状态 temp_chm_state_info as ( select distinct b.groupname , b.recipe_group , b.recipe , b.productfamily , e.eqpid , nvl(p.is_ppid_enable,'0') is_ppid_enable, nvl(f.note ,'0') note , nvl( e.full_config ,'0') full_config from basic_info b left join eqp_list e on 1=1 left join ( select recipelist ,eqpid, is_ppid_enable from p_MFG_create.RPT_ODST_PRDRAP_PPID_CHK where 1=1 and recipelist in (select recipe from basic_info) group by recipelist ,eqpid,is_ppid_enable ) p on b.recipe = p.recipelist and e.eqpid = p.eqpid left join eqp_flag f on b.groupname = f.eqpgroup --and b.recipe_group = f.recipegroup and b.recipe = f.recipename and b.productfamily = f.productfamily and e.eqpid = f.eqpid left join P_MFG_CREATE.RPT_TGT_RAP_STATICSTATE_CONFIG r on r.category ='if recipe active' and b.groupname = r.eqpgroup --and b.recipe_group = r.recipegroup and b.recipe = r.recipename and b.productfamily = r.productfamily where nvl(r.note,'Y') ='Y' ), --chamber plan rls count 和 act rls count chm_state_info as ( select groupname , recipe_group , recipe , productfamily , sum(note) Plan_rls , sum(is_ppid_enable) ACT_rls from temp_chm_state_info group by groupname , recipe_group , recipe , productfamily ), --整机count eqp_state_info as ( select groupname , recipe_group , recipe , productfamily , sum(case when a.Plan_total_cnt = c.total_cnt then 1 else 0 end ) Plan_total_cnt , sum(case when a.act_total_cnt = c.total_cnt then 1 else 0 end ) act_total_cnt , max(full_config) full_config from ( select groupname , recipe_group , recipe , productfamily , substr( eqpid ,1,instr(eqpid,'_')-1) eqpid, max(full_config) full_config , sum(note) Plan_total_cnt , sum(is_ppid_enable) act_total_cnt from temp_chm_state_info where eqpid like '%/_%' escape '/' group by groupname , recipe_group , recipe , productfamily , substr( eqpid ,1,instr(eqpid,'_')-1) ) a join (select substr(eqpid,1 ,7 ) eqpid , count(1) total_cnt from CENTERDB.RPT_BRT_EQP_LST where CONSTRUCTTYPE ='Chamber' group by substr(eqpid,1 ,7 )) c on a.eqpid = c.eqpid group by groupname , recipe_group , recipe , productfamily ), temp_detail_info as ( select s.groupname, s.recipe_group, s.recipe, s.productfamily, s.capability, s.stagename, nvl(r.note,'Y') if_recipe_active ,nvl(r1.note,'1') MPS_Ratio , s.tgtuptime , s.tgtme , s.wph , s.tgtuptime*s.tgtme*s.wph*720 k_unit , null admin_flag , null dedicate_tool_count , null dedicate_ratio , c.plan_rls, case when s.step_cnt*m.mps_modify*nvl(r1.note,'1') !=0 and ( ( s.step_cnt*m.mps_modify*nvl(r1.note,'1') ) / (s.tgtuptime*s.tgtme*s.wph*720) ) >=1 then c.plan_rls / ( ( s.step_cnt*m.mps_modify*nvl(r1.note,'1') ) / (s.tgtuptime*s.tgtme*s.wph*720) ) when s.step_cnt*m.mps_modify*nvl(r1.note,'1') !=0 and ( ( s.step_cnt*m.mps_modify*nvl(r1.note,'1') ) / (s.tgtuptime*s.tgtme*s.wph*720) ) <1 then c.plan_rls / 1 end plan_path , case when floor(c.plan_rls/e.full_config) !=0 then e.Plan_total_cnt/floor(c.plan_rls/e.full_config) end Plan_total_ratio, c.ACT_rls , case when s.step_cnt*m.mps_modify*nvl(r1.note,'1') !=0 and ( ( s.step_cnt*m.mps_modify*nvl(r1.note,'1') ) / (s.tgtuptime*s.tgtme*s.wph*720) )>=1 then c.ACT_rls / ( ( s.step_cnt*m.mps_modify*nvl(r1.note,'1') ) / (s.tgtuptime*s.tgtme*s.wph*720) ) when s.step_cnt*m.mps_modify*nvl(r1.note,'1') !=0 and ( ( s.step_cnt*m.mps_modify*nvl(r1.note,'1') ) / (s.tgtuptime*s.tgtme*s.wph*720) )<1 then c.ACT_rls / 1 end act_path , case when floor(c.ACT_rls/e.full_config) !=0 then e.act_total_cnt/floor(c.ACT_rls/e.full_config) end act_total_ratio , s.step_cnt*to_number(m.mps_modify) mps_modify , 4 rank , case when s.tgtuptime*s.tgtme*s.wph*720 !=0 then ( s.step_cnt*m.mps_modify*nvl(r1.note,'1') ) / (s.tgtuptime*s.tgtme*s.wph*720) end demand , nvl(e.act_total_cnt,'0') act_total_cnt, nvl(e.Plan_total_cnt,'0') Plan_total_cnt from basic_info s LEFT JOIN P_MFG_CREATE.RPT_TGT_RAP_STATICSTATE_CONFIG r on r.category ='if recipe active' and s.groupname = r.eqpgroup --and s.recipe_group = r.recipegroup and s.recipe = r.recipename and s.productfamily = r.productfamily LEFT JOIN P_MFG_CREATE.RPT_TGT_RAP_STATICSTATE_CONFIG r1 ON r1.category ='MPS Ratio' and r1.mfgmonth ='2025-M09' and s.groupname = r1.eqpgroup --and s.recipe_group = r1.recipegroup and s.recipe = r1.recipename and s.productfamily = r1.productfamily left join mps_info m on s.productfamily = m.productfamily left join chm_state_info c on s.groupname = c.groupname and s.recipe_group = c.recipe_group and s.recipe = c.recipe and s.productfamily = c.productfamily left join eqp_state_info e on s.groupname = e.groupname and s.recipe_group = e.recipe_group and s.recipe = e.recipe and s.productfamily = e.productfamily ), detail_info as ( select groupname, recipe_group, recipe, productfamily, capability, stagename, if_recipe_active , MPS_Ratio , tgtuptime , tgtme , wph , k_unit , admin_flag , dedicate_tool_count , dedicate_ratio , case when if_recipe_active='Y' then plan_rls end plan_rls, case when if_recipe_active='Y' then plan_path end plan_path, case when if_recipe_active='Y' then Plan_total_ratio end Plan_total_ratio, case when if_recipe_active='Y' then ACT_rls end ACT_rls, case when if_recipe_active='Y' then act_path end act_path, case when if_recipe_active='Y' then act_total_ratio end act_total_ratio, case when if_recipe_active='Y' then mps_modify end mps_modify, 4 rank , case when if_recipe_active='Y' then demand end demand, case when if_recipe_active='Y' then act_total_cnt end act_total_cnt, case when if_recipe_active='Y' then Plan_total_cnt end Plan_total_cnt from temp_detail_info ), chm_state_info_recipe as ( select groupname , recipe_group , recipe , sum(note) Plan_rls , sum(is_ppid_enable) ACT_rls from ( select groupname , recipe_group , recipe , eqpid , nvl(max(is_ppid_enable),'0') is_ppid_enable, nvl( max(note) ,'0') note from temp_chm_state_info group by groupname , recipe_group , recipe , eqpid ) group by groupname , recipe_group , recipe ), --by recipe整机count,直接用by recipe整机数/demand整机数,不要by prod计算再权 eqp_state_info_recipe as ( select groupname , recipe_group , recipe , count(distinct Plan_total_eqpid ) Plan_total_cnt , count(distinct act_total_eqpid ) act_total_cnt , max(full_config) full_config from ( select groupname , recipe_group , recipe , productfamily , case when a.Plan_total_cnt = c.total_cnt then a.eqpid end Plan_total_eqpid , case when a.act_total_cnt = c.total_cnt then a.eqpid end act_total_eqpid , full_config from ( select groupname , recipe_group , recipe , productfamily , substr( eqpid ,1,instr(eqpid,'_')-1) eqpid, max(full_config) full_config , sum(note) Plan_total_cnt , sum(is_ppid_enable) act_total_cnt from temp_chm_state_info where eqpid like '%/_%' escape '/' group by groupname , recipe_group , recipe , productfamily , substr( eqpid ,1,instr(eqpid,'_')-1) ) a join (select substr(eqpid,1 ,7 ) eqpid , count(1) total_cnt from CENTERDB.RPT_BRT_EQP_LST where CONSTRUCTTYPE ='Chamber' group by substr(eqpid,1 ,7 )) c on a.eqpid = c.eqpid ) group by groupname , recipe_group , recipe ), recipe_detail_info as ( select a.groupname , a.recipe_group , a.recipe , a.productfamily ,a.capability , a.stagename , a.if_recipe_active , a.MPS_Ratio , a.tgtuptime , a.tgtme , a.wph , a.k_unit , a.admin_flag , a.dedicate_tool_count , a.dedicate_ratio , c.plan_rls , case when demand >=1 then c.plan_rls / demand when demand <1 and demand>0 then c.plan_rls / 1 end plan_path , case when floor(c.plan_rls/r.full_config) !=0 then r.Plan_total_cnt/floor(c.plan_rls/r.full_config) end Plan_total_ratio , c.ACT_rls , case when demand >=1 then c.ACT_rls / demand when demand <1 and demand>0 then c.ACT_rls / 1 end act_path , case when floor(c.ACT_rls/r.full_config) !=0 then r.act_total_cnt/floor(c.ACT_rls/r.full_config) end act_total_ratio , a.mps_modify , a.rank from ( select groupname , recipe_group , recipe , rtrim(regexp_replace(xmlagg(XMLparse(content productfamily||',' )order by productfamily ).getclobval(),'([^,]+)(,\1)+','\1'),',') productfamily , capability , rtrim(regexp_replace(xmlagg(XMLparse(content to_char(stagename)||',' )order by to_char(stagename) ).getclobval(),'([^,]+)(,\1)+','\1'),',') stagename , null if_recipe_active , null MPS_Ratio , avg(tgtuptime) tgtuptime , avg(tgtme) tgtme , null wph , null k_unit , null admin_flag , null dedicate_tool_count , null dedicate_ratio , --case when sum(mps_modify)>0 then sum(mps_modify*plan_path)/sum(mps_modify) end plan_path , --case when sum(mps_modify)>0 then sum(mps_modify*Plan_total_ratio)/sum(mps_modify) end Plan_total_ratio , --case when sum(mps_modify)>0 then sum(mps_modify*act_path)/sum(mps_modify) end act_path , --case when sum(mps_modify)>0 then sum(mps_modify*act_total_ratio)/sum(mps_modify) end act_total_ratio , sum(demand) demand , sum(mps_modify) mps_modify , 3 rank from detail_info GROUP BY groupname , recipe_group , recipe , capability ) a left join chm_state_info_recipe c on a.groupname = c.groupname and a.recipe_group = c.recipe_group and a.recipe =c.recipe left join eqp_state_info_recipe r on a.groupname = r.groupname and a.recipe_group = r.recipe_group and a.recipe =r.recipe ), chm_state_info_recipegrp as ( select groupname , recipe_group , sum(note) Plan_rls , sum(is_ppid_enable) ACT_rls from ( select groupname , recipe_group , eqpid , nvl(max(is_ppid_enable),'0') is_ppid_enable, nvl( max(note) ,'0') note from temp_chm_state_info group by groupname , recipe_group , eqpid ) group by groupname , recipe_group ), temp_dedicate_info as ( select distinct eqpgroup , eqpid , recipename from P_MFG_CREATE.RPT_TGT_RAP_STATICSTATE_CONFIG where category ='eqpid' and note ='1' and mfgmonth ='2025-M09' and EQPGROUP||RECIPENAME||PRODUCTFAMILY NOT IN ( select EQPGROUP||RECIPENAME||PRODUCTFAMILY from P_MFG_CREATE.RPT_TGT_RAP_STATICSTATE_CONFIG r where r.category ='if recipe active' and note ='N' ) ) , dedicate_info as ( select recipegroup , eqpgroup, count(distinct eqpid ) dedicate_tool_count from ( select distinct eqpgroup , eqpid , recipename , recipegroup , count(distinct recipegroup ) over(partition by eqpid ) cnt from ( select distinct t.eqpgroup , t.eqpid , t.recipename , nvl(s.recipe_group , t.recipename ) recipegroup from temp_dedicate_info t join p_MFG_create.RPT_ODST_PRDRAP_STATICSTATE s on t.eqpgroup = s.groupname and t.recipename = s.recipe ) ) where cnt =1 group by recipegroup , eqpgroup ) , --by recipe group的plan/act整机ratio:用recipename整机ratio结果按MPS权平均 recipegrp_total_ratio as ( select groupname , recipe_group ,capability , case when sum(mps_modify)>0 then sum(mps_modify*Plan_total_ratio)/sum(mps_modify) end Plan_total_ratio , case when sum(mps_modify)>0 then sum(mps_modify*act_total_ratio)/sum(mps_modify) end act_total_ratio from recipe_detail_info group by groupname , recipe_group ,capability ), recipegrp_detail_info as ( select a.groupname , a.recipe_group , a.recipe , a.productfamily ,a.capability , a.stagename , a.if_recipe_active , a.MPS_Ratio , a.tgtuptime , a.tgtme , a.wph , a.k_unit , a.admin_flag , nvl(d.dedicate_tool_count,0) dedicate_tool_count , nvl(case when demand!=0 then d.dedicate_tool_count/a.demand end,0) dedicate_ratio , c.plan_rls , case when demand >=1 then c.plan_rls / demand when demand <1 and demand>0 then c.plan_rls / 1 end plan_path , r.Plan_total_ratio , c.ACT_rls , case when demand >=1 then c.ACT_rls / demand when demand <1 and demand>0 then c.ACT_rls / 1 end act_path , r.act_total_ratio , a.mps_modify , a.rank from ( select groupname , recipe_group , rtrim(regexp_replace(xmlagg(XMLparse(content to_char(recipe)||',' )order by to_char(recipe) ).getclobval(),'([^,]+)(,\1)+','\1'),',') recipe, rtrim(regexp_replace(xmlagg(XMLparse(content to_char(productfamily)||',' )order by to_char(productfamily) ).getclobval(),'([^,]+)(,\1)+','\1'),',') productfamily , capability , rtrim(regexp_replace(xmlagg(XMLparse(content to_char(stagename)||',' )order by to_char(stagename) ).getclobval(),'([^,]+)(,\1)+','\1'),',') stagename , null if_recipe_active , null MPS_Ratio , avg(tgtuptime) tgtuptime , avg(tgtme) tgtme , null wph , null k_unit , null admin_flag , --case when sum(mps_modify)>0 then sum(mps_modify*plan_path)/sum(mps_modify) end plan_path , --case when sum(mps_modify)>0 then sum(mps_modify*Plan_total_ratio)/sum(mps_modify) end Plan_total_ratio , --case when sum(mps_modify)>0 then sum(mps_modify*act_path)/sum(mps_modify) end act_path , --case when sum(mps_modify)>0 then sum(mps_modify*act_total_ratio)/sum(mps_modify) end act_total_ratio , sum(mps_modify) mps_modify , 2 rank , sum(demand) demand from detail_info GROUP BY groupname , recipe_group ,capability ) a left join chm_state_info_recipegrp c on a.groupname = c.groupname and a.recipe_group = c.recipe_group left join dedicate_info d on a.recipe_group = d.recipegroup and a.groupname = d.eqpgroup left join recipegrp_total_ratio r on a.recipe_group = r.recipe_group and a.groupname = r.groupname and a.capability = r.capability ), chm_state_info_eqpgrp as ( select groupname , sum(note) Plan_rls , sum(is_ppid_enable) ACT_rls from ( select groupname , eqpid , nvl(max(is_ppid_enable),'0') is_ppid_enable, nvl( max(note) ,'0') note from temp_chm_state_info group by groupname , eqpid ) group by groupname ), --by Eqp group plan/act路宽汇总: by recipe group 汇总的路宽结果再用MPS权平均 eqpgrp_path as ( select groupname , capability , case when sum(mps_modify)>0 then sum(mps_modify*plan_path)/sum(mps_modify) end plan_path , case when sum(mps_modify)>0 then sum(mps_modify*act_path)/sum(mps_modify) end act_path from recipegrp_detail_info group by groupname , capability ), --by eqp group的plan/act整机ratio:用recipe group整机ratio结果按MPS权平均 eqpgrp_total_ratio as ( select groupname , capability , case when sum(mps_modify)>0 then sum(mps_modify*Plan_total_ratio)/sum(mps_modify) end Plan_total_ratio , case when sum(mps_modify)>0 then sum(mps_modify*act_total_ratio)/sum(mps_modify) end act_total_ratio from recipegrp_detail_info group by groupname , capability ), dedicate_info_eqpgrp as ( select eqpgroup , sum(dedicate_tool_count) dedicate_tool_count from dedicate_info group by eqpgroup ), tmp_eqpgrp_detail_info as ( select groupname , --rtrim(regexp_replace(xmlagg(XMLparse(content recipe_group||',' )order by recipe_group ).getclobval(),'([^,]+)(,\1)+','\1'),',') recipe_group , rtrim(xmlagg(xmlparse(content recipe_group||',') order by recipe_group).getclobval(),',') recipe_group , rtrim(regexp_replace(xmlagg(XMLparse(content recipe||'/' )order by recipe ).getclobval(),'([^,]+)(,\1)+','\1'),',') recipe , rtrim(regexp_replace(xmlagg(XMLparse(content productfamily||',' )order by productfamily ).getclobval(),'([^,]+)(,\1)+','\1'),',') productfamily , capability , rtrim(regexp_replace(xmlagg(XMLparse(content stagename||',' )order by stagename ).getclobval(),'([^,]+)(,\1)+','\1'),',') stagename , null if_recipe_active , null MPS_Ratio , avg(tgtuptime) tgtuptime , avg(tgtme) tgtme , null wph , null k_unit , null admin_flag , --case when sum(mps_modify)>0 then sum(mps_modify*act_total_ratio)/sum(mps_modify) end act_total_ratio , --case when sum(mps_modify)>0 then sum(mps_modify*Plan_total_ratio)/sum(mps_modify) end Plan_total_ratio , --case when sum(mps_modify)>0 then sum(mps_modify*plan_path)/sum(mps_modify) end plan_path , --case when sum(mps_modify)>0 then sum(mps_modify*act_path)/sum(mps_modify) end act_path , sum(mps_modify) mps_modify , 1 rank , sum(demand) demand from detail_info GROUP BY groupname , capability ), eqpgrp_detail_info as ( select s.groupname ,s.recipe_group ,s.recipe , s.productfamily , s.capability ,stagename ,if_recipe_active , MPS_Ratio , tgtuptime , tgtme , wph , k_unit , nvl(r2.note,'Y') admin_flag , nvl(d.dedicate_tool_count,0) dedicate_tool_count, nvl(case when demand!=0 then d.dedicate_tool_count/s.demand end,0) dedicate_ratio , c.plan_rls , e.plan_path , r.Plan_total_ratio , c.act_rls , e.act_path , r.act_total_ratio , mps_modify , 1 rank from tmp_eqpgrp_detail_info s LEFT JOIN P_MFG_CREATE.RPT_TGT_RAP_STATICSTATE_CONFIG r2 ON r2.category ='是否需要路宽管理' and s.groupname = r2.eqpgroup left join chm_state_info_eqpgrp c on s.groupname = c.groupname left join dedicate_info_eqpgrp d on s.groupname = d.eqpgroup left join eqpgrp_path e on s.groupname = e.groupname and s.capability = e.capability left join eqpgrp_total_ratio r on s.groupname = r.groupname and s.capability = r.capability ) select recipe from recipegrp_detail_info union all select recipe from eqpgrp_detail_info;
09-03
WITH TMP AS ( SELECT DISTINCT ROW_NUMBER() OVER ( PARTITION BY T3.PROJECT_NO, T3.PIPE_NO, T4.MAT_NO ORDER BY T4.ID ) AS idx, T1.PROJECT_NO, T1.PIPE_NO, T1.PIPE_VERSION, T6.PROJ_ID || ' ' || T6.PROJ_NAME AS PRINT_NAME, T1.ORDER_NO, T5.SHOP_MAT_ORDER_NO, T3.BLOCK, T3.DRAW_NO, T3.PIPE_CLASS, NVL(T7.DESCRIPTION, T4.MAT_DESP) MATERIAL_DESP, T3.PAGE_NO, NVL(T4.OLD_LENGTH, T3.LENGTH) AS "LENGTH", CASE WHEN T4.IS_BENDING = 'Y' THEN NVL(T4.GROOVE_QTY,0) || '弯' ELSE TO_CHAR(NVL(T4.GROOVE_QTY,0)) END GROOVE, T5.CUT_REMARK, T5.HEAT_NO, T3.IS_THROUGH_CABIN, T3.MODIFY_TYPE, T1.ORDER_NO, T4.MAT_NO FROM CP_PIPE_PRE_WORK_ORDER_PIPE T1 LEFT JOIN CP_PIPE_PRE_WORK_ORDER T2 ON T1.ORDER_NO = T2.ORDER_NO LEFT JOIN CP_PIPE_DESIGN_INFO T3 ON T1.PROJECT_NO = T3.PROJECT_NO AND T1.PIPE_NO = T3.PIPE_NO AND T1.PIPE_VERSION = T3.PIPE_VERSION LEFT JOIN CP_PIPE_PART_DESIGN_INFO T4 ON T3.PROJECT_NO = T4.PROJECT_NO AND T3.PIPE_NO = T4.PIPE_NO AND T3.PIPE_VERSION = T4.PIPE_VERSION LEFT JOIN CP_PIPE_PART_PROD_INFO T5 ON T4.PROJECT_NO = T5.PROJECT_NO AND T4.PIPE_NO = T5.PIPE_NO AND T4.PIPE_VERSION = T5.PIPE_VERSION AND T4.PART_NO = T5.PART_NO LEFT JOIN PROJ T6 ON T1.PROJECT_NO = T6.PROJ_ID LEFT JOIN ERP_INVENTORY_PART T7 ON T4.PART_NO = T7.PART_NO WHERE T3.IS_TOP_VERSION = 'Y' AND T3.IS_DELETE = 'N' AND T4.IS_DELETE = 'N' AND T4.MAT_NO IS NOT NULL AND T3.IS_PAUSE = 'N' AND T4.IS_BUY = 'N' AND T1.ORDER_NO = ? AND T2.PROCESS = ? ) SELECT T1.idx, T1.ORDER_NO, T1.PROJECT_NO, T1.PIPE_NO, T1.PIPE_VERSION, T1.PRINT_NAME, T2.SHOP_MAT_ORDER_NO, T1.BLOCK, T1.DRAW_NO, T1.PIPE_CLASS, T1.MATERIAL_DESP, T1.PAGE_NO, T1."LENGTH", T1.GROOVE, T1.CUT_REMARK, T1.HEAT_NO, T1.IS_THROUGH_CABIN, T1.MODIFY_TYPE, T4.MAT_NO FROM TMP T1 LEFT JOIN ( SELECT ORDER_NO, REGEXP_REPLACE( (LISTAGG(SHOP_MAT_ORDER_NO, ',') WITHIN GROUP (ORDER BY SHOP_MAT_ORDER_NO)), '([^,]+)(,\1)*(,|$)', '\1\3' ) AS SHOP_MAT_ORDER_NO FROM ( SELECT DISTINCT ORDER_NO, SHOP_MAT_ORDER_NO FROM TMP ) WHERE SHOP_MAT_ORDER_NO IS NOT NULL GROUP BY ORDER_NO ) T2 ON T1.ORDER_NO = T2.ORDER_NO ORDER BY T1.MATERIAL_DESP, T1.PIPE_NO ### Cause: java.sql.SQLSyntaxErrorException: ORA-00918: 未明确定义列
最新发布
09-25
with required_exams as ( -- 获取 lookup 中配置的有效考试信息,并按 type 拆分 select li.item_code, li.item_name, '技术复核' as exam_type from tpl_lookup_item_t li where li.classify_code = 'INTERVIEW_EXAM_INFO' and li.status = '1' and (instr(li.item_attr4, '技术复核') > 0) union all select li.item_code, li.item_name, '综合复核' as exam_type from tpl_lookup_item_t li where li.classify_code = 'INTERVIEW_EXAM_INFO' and li.status = '1' and (instr(li.item_attr4, '综合复核') > 0)), required_count as ( -- 统计每种类型需要通过的考试数量 select exam_type, count(*) as required_count from required_exams group by exam_type), user_passed_exams as ( -- 查询用户已通过的考试记录,并按考试类型分类 select case when instr(li.item_attr4, '技术复核') > 0 then '技术复核' when instr(li.item_attr4, '综合复核') > 0 then '综合复核' end as exam_type, t.user_id, t.emp_num, t.exam_code, t.exam_name from omp_exam_record_t t left join tpl_lookup_item_t li on li.classify_code = 'INTERVIEW_EXAM_INFO' and li.status = '1' and li.item_code = t.exam_code where t.is_pass = '1' and (instr(li.item_attr4, '技术复核') > 0 or instr(li.item_attr4, '综合复核') > 0) group by case when instr(li.item_attr4, '技术复核') > 0 then '技术复核' when instr(li.item_attr4, '综合复核') > 0 then '综合复核' end, t.user_id, t.emp_num, t.exam_code, t.exam_name), user_passed_count as ( -- 统计每个用户在每种类型下通过的考试数量 select user_id, emp_num, exam_type, count(*) as passed_count from user_passed_exams group by user_id, emp_num, exam_type), all_exam_per_user_type as ( -- 为每个用户生成每个考试类型下的所有考试 select distinct u.user_id, u.emp_num, re.exam_type, re.item_code as exam_code, re.item_name as exam_name from required_exams re cross join (select distinct user_id, emp_num from user_passed_exams) u), user_exam_status as ( -- 标记每个考试是否通过 select a.user_id, a.emp_num, a.exam_type, a.exam_code, a.exam_name, case when p.exam_code is not null then '已通过' else '未通过' end as pass_status from all_exam_per_user_type a left join user_passed_exams p on a.user_id = p.user_id and a.exam_code = p.exam_code and a.exam_type = p.exam_type), exam_status_aggregation as ( -- 按用户和类型,聚合通过和未通过的考试信息 select user_id, emp_num, exam_type, listagg(case when pass_status = '已通过' then exam_code end, ',') within group (order by exam_code) as passed_exam_codes, listagg(case when pass_status = '已通过' then exam_name end, ',') within group (order by exam_code) as passed_exam_names, listagg(case when pass_status = '未通过' then exam_code end, ',') within group (order by exam_code) as failed_exam_codes, listagg(case when pass_status = '未通过' then exam_name end, ',') within group (order by exam_code) as failed_exam_names from user_exam_status group by user_id, emp_num, exam_type) -- 最终结果:用户通过状态 + 通过/未通过的考试列表 select e.user_id, e.emp_num, ut.lname, e.exam_type, rc.required_count, case when upc.passed_count is null then 0 else upc.passed_count end passed_count, case when upc.passed_count >= rc.required_count then '已全部通过' else '未全部通过' end as full_pass_status, e.passed_exam_codes, e.passed_exam_names, e.failed_exam_codes, e.failed_exam_names from exam_status_aggregation e join required_count rc on e.exam_type = rc.exam_type left join tpl_user_t ut on e.user_id = ut.user_id left join user_passed_count upc on e.user_id = upc.user_id and e.exam_type = upc.exam_type where (e.user_id, e.exam_type) in (select log.user_id as userid, log.interview_type as interviewtype -- log.operate_type as operatetype, -- log.operate_cause as operatecause, -- to_char(log.creation_date, 'YYYY-MM-DD HH24:MI:SS') creation_date from omp_emp_reviewer_log_t log left join omp_local_org_t org_v on org_v.id = log.local_org_id left join omp_org_config_t org on org.hw_org_code = log.dept_id and org.status = 'ACTIVE' where log.operate_type like '%自动失效%' and log.operate_cause like '%复核官没有通过考试或者没有参考试,系统自动失效资质%' order by log.creation_date desc) order by e.user_id, e.exam_type 帮我优化下SQL
07-26
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值