请大佬帮忙看看这段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