要计算卡的消费总额和卡的余额这样查出来是错的该怎么调整?
act_vip_card_saving 卡余额记录
act_pay_log 卡消费记录
SELECt case when sum(I.balance) is null then 0 else sum(I.balance) end as _balance,
case when sum(H.money_sum) is null then 0 else sum(H.money_sum) end as
_consuming from act_person_info A
left outer join act_vip_account E on A.id = E.person_id
left outer join act_vip_card F on E.id = F.account_id
left outer join act_pay_log H on F.uuid = H.uuid
left outer join act_vip_card_saving I on F.uuid = I.uuid
GROUP BY A.id ORDER BY _balance desc
sql多表多个sum查询数据,该怎么调整
答案:2 悬赏:30 手机版
解决时间 2021-02-18 22:47
- 提问者网友:心牵心
- 2021-02-18 04:26
最佳答案
- 五星知识达人网友:我住北渡口
- 2021-02-18 05:25
sum放在整个case 判断的外面
sum(case l.balance is null then 0 else l.balance end)
sum(case l.balance is null then 0 else l.balance end)
全部回答
- 1楼网友:春色三分
- 2021-02-18 06:12
select customer, sum(s_count) count into 新的表名 from table group by customer
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯