weixin_43078650 2020-04-23 21:42 采纳率: 0%
浏览 155
已结题

请大佬帮忙看看这段sql还能怎么优化一下

请大佬帮忙看看这段sql还能怎么优化一下,目前看group by还是有问题,执行计划看group by还是有问题的。。。

select 
c.code as deptCode,
a.item_id as itemId,
a.item_code as itemCode,
sum(a.adjust_num) as adjustNum,
0 as status,
group_concat(a.id separator '-') as detailIds, 
c.detail_reason as reasonCode
    from 表 a,表 c
    where c.ware_id = #{wareId}
    and a.ware_id = #{wareId}
    and c.id = a.adjust_id
    and a.gmt_modified between #{Start} and #{End}
    and a.status = 2
    and c.describe = #{describe}
    and (c.source_mode is null or c.source_mode = 14)
    <if test="itemCode != null">
      and a.item_code = #{itemCode}
    </if>
    <if test="deptCode != null">
      and c.dept_code = #{deptCode}
    </if>
    <if test="deptCodes != null and deptCodes.size > 0">
      and c.dept_code in
      <foreach item="iDeptCode" collection="deptCodes" open="(" separator="," close=")">
        #{iDeptCode}
      </foreach>
    </if>
    <if test="excludeDetailIds != null and excludeDetailIds.size > 0">
      and a.id not in
      <foreach item="iExcludeDetailId" collection="excludeDetailIds" open="(" separator="," close=")">
        #{iExcludeDetailId}
      </foreach>
    </if>
    <if test="reasonCode != null">
      and c.detail_reason = #{reasonCode}
    </if>
    group by c.dept_code,a.item_code

执行计划:第一行是表c,第二行是表a
图片说明

  • 写回答

3条回答 默认 最新

  • threenewbee 2020-04-24 00:24
    关注
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?