【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

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值