可以使用SUM函数来统计所有结果行的quantity的总和。将原始的查询语句改为以下形式:

<select id="selectVmiListForQuantity" parameterType="java.lang.String" resultType="org.jeecg.modules.odsMaterialDocumentService.entity.VmiMaterialDocument">
    SELECT
        SUM(QuantityInEntryUnit - ArtificialConsume - AutomaticConsume) as totalQuantity
    FROM
        vmi_materialdocument
    <where>
        <if test="postingDate != null and postingDate != ''">
            DATE_FORMAT(PostingDate, '%Y-%m') = DATE_FORMAT(#{time}, '%Y-%m')
        </if>
        <if test="type == '1'">
            AND (QuantityInEntryUnit - ArtificialConsume - AutomaticConsume) > 0
        </if>
        <if test="type == '2'">
            AND (QuantityInEntryUnit - ArtificialConsume - AutomaticConsume) <= 0
        </if>
    </where>
</select>

在修改后的查询语句中,使用SUM函数将quantity的值进行求和,并将结果命名为totalQuantity。这样就可以得到所有结果行的quantity的总和。

select id=selectVmiListForQuantity parameterType=javalangString resultType=orgjeecgmodulesodsMaterialDocumentServiceentityVmiMaterialDocument SELECT Material as material Batch as bat

原文地址: https://www.cveoy.top/t/topic/i63r 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录