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
【Mysql】mysql求和sum,去除order_id重复的数据,其余数据进行求和操作
最新推荐文章于 2024-07-30 14:50:46 发布
此博客详细描述了一种SQL查询,用于计算特定条件下订单的前后余额变化总和。通过LEFT JOIN连接多个表,并使用IF条件语句对order_id、用户信息、商品属性等进行筛选,最终按订单ID分组并求和。
摘要由CSDN通过智能技术生成