几个大表组合查询,如何提高效率?

SELECT a.longbarcode ,e.materialname 条码品牌,b.logisticsid 物流号,b.inshiftid 班次,b.boxid 码垛次序  ,

 a.fxjid 封箱机号,a.laneno 分拣道号,a.inserttime 一号工程码打码时间 ,c.createtime 物流建立时间,b.producetime 码垛时间,c.intime 上架时间,

c.nowposition 位置,c.lane 排,c.bay 列,c.floor 层,a.orderstatus

FROM

 (SELECT longbarcode,inserttime,fxjid,laneno,orderstatus FROM T_ARTICALINPICK_INTF 

where 1=1 

${if(len(barcode)> 0,"and  longbarcode ='"+barcode+"'",

  if((len(fxjid)==0) && (len(brandcode)==0),

       "",

       if(len(fxjid)==0 ,

         "and substr(longbarcode,0,16)='"+brandcode+"'",

         if(len(brandcode)==0,

          "and fxjid='"+fxjid+"'",

          "and substr(longbarcode,0,16)='"+brandcode+"'"+"and fxjid='"+fxjid+"'" )

        )

    )+"and to_char(inserttime,"+"'"+"yyyy-mm-dd hh24:mi:ss"+"')"+" between "+"'"+starttime +"'"+" and"+ "'"+endtime+"'"

  )

}

 )  a

LEFT JOIN

( select *  from (

 SELECT barcode,logisticsid,boxid,inshiftid,producetime FROM T_UNIT

 UNION ALL

 SELECT barcode,logisticsid,boxid, inshiftid,producetime FROM T_UNITHISTORY)

 where 1=1 ${if(len(barcode)> 0,"and  barcode ='"+barcode+"'",

"and to_char(producetime,"+"'"+"yyyy-mm-dd hh24:mi:ss"+"')"+" between "+"'"+starttime +"'"+" and"+ "'"+endtime+"'")

         }

) b ON b.barcode=a.longbarcode

LEFT JOIN

( select * from (

SELECT logisticsid,materialid, createtime,intime,nowposition,lane,bay,floor  FROM T_LOGISTICS

UNION ALL

SELECT logisticsid,materialid, createtime,intime,nowposition,lane,bay,floor FROM T_LOGISTICSHISTORY)

 where 1=1 ${if(len(barcode)> 0,"",

 "and to_char(createtime,"+"'"+"yyyy-mm-dd hh24:mi:ss"+"')"+" between "+"'"+starttime +"'"+" and"+ "'"+endtime+"'")

                 }

) c ON c.logisticsid=b.logisticsid 

LEFT JOIN

( SELECT materialname,barcode FROM c_material WHERE materialname LIKE'%)' ) e ON e.barcode=SUBSTR(a.longbarcode,1,16)

order by  a.inserttime desc

FineReport yzm128012 发布于 2023-4-22 15:10
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共1回答
最佳回答
0
1592Lv6高级互助
发布于2023-4-22 15:19

找数据库管理员加相关索引

  • 2关注人数
  • 279浏览人数
  • 最后回答于:2023-4-22 15:19
    请选择关闭问题的原因
    确定 取消
    返回顶部