【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 g2LEFT JOIN gz_order
·
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

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐
所有评论(0)