请大佬帮忙看看这段sql语法上面能怎么优化一下

请大佬帮忙看看这段sql语法上面能怎么优化一下

select...
from 表 A a,表B b,表C c
 where c.waree_id = #{wareId}
    and a.ware_id = #{wareId}
    and b.warehouse_id = #{wareId}
    and c.id = a.inventory_id
    and a.id = b.detail_id
    and a.gmt_modified between #{adjustrStart} and #{adjustEnd}
    and a.status = 2
    and c.adjust_describe = #{adjustDescribe}
    <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="serialNo != null">
      and b.serial_no = #{serialNo}
    </if>
    <if test="reasonCode != null">
      and c.detail_reason = #{reasonCode}
    </if>

    and a.id = b.detail_id
    group by b.serial_no order by b.last_print_date desc

https://www.cnblogs.com/xc-chejj/p/11244748.html

不需要特别优化,你给的条件值很多,本身sql跑的就会很快,只是你的写法where后面紧跟的三句可以关联一下
c.waree_id = a.ware_id
and a.ware_id = b.warehouse_id
and b.warehouse_id = #{wareId}

最后group by前面一句重复了上面的