【Mysql】mysql求和sum,去除order_id重复的数据,其余数据进行求和操作

SELECT SUM(totalSum.before_change_balance-totalSum.after_change_balance) FROM(SELECT DISTINCT g2.order_id,g2.							     	before_change_balance,g2.after_change_balance FROM gz_wallet_shop_log g2
        LEFT JOIN gz_order g1 ON g1.id=g2.order_id
        LEFT JOIN gz_login_user g3 on g2.user_id=g3.id
        WHERE types=1
        <if test="id != null and id !='' ">
            and g1.id= #{id}
        </if>
        <if test="accounts != null and accounts !='' ">
            and g3.accounts= #{accounts}
        </if>
        <if test="productName != null and productName !='' ">
            and g1.product_name= #{productName}
        </if>
        <if test="productId != null and productId !='' ">
            and g1.product_id= #{productId}
        </if>
        <if test="delistingStatus != null and delistingStatus !='' ">
            and g1.delisting_status= #{delistingStatus}
        </if>
        <if test="begin != null and begin !='' and  end != null and end !='' ">
            and (g1.create_time between #{begin} and #{end})
        </if>
        <if test="isReleaseOrder != null and isReleaseOrder !='' ">
            and g1.is_release_order= #{isReleaseOrder}
        </if>
        <if test="userName != null and userName !='' ">
            and g1.user_name= #{userName}
        </if>
        <if test="realName != null and realName !='' ">
            and g1.real_name= #{realName}
        </if>
        <if test="shopId != null and shopId !='' ">
            and g1.shop_id= #{shopId}
        </if>
        <if test="paymentChannel != null and paymentChannel !='' ">
            and g1.payment_channel= #{paymentChannel}
        </if>
        GROUP BY g2.order_id)AS totalSum


版权声明:本文为kuikuiaile原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。