精彩sql 帐户系统余额统计是否正确检查

sql 分组取最大最小数和sum数据.

【SQL精彩语句】按某一字段分组取最大(小)值所在行的数据

自己的sql. group by 默认是取第一条的.

全量方案:

select a.balance,summ.total from acount a join (select f.帐户表_id, sum(money) total from 帐户表_流水表 f join   (select 帐户表_id from 帐户表_流水表 where balance is not NULL order by id desc limit 10) idt on f.帐户表_id=idt.帐户表_id group by f.帐户表_id ) summ on a.id=summ.帐户表_id where a.balance !=summ.total;
  基于某行之后的方案: 基于group by获取的是第一条数据.

select tt.count,a.id,tt.帐户表_id,a.balance,tt.balance1+money from 帐户表 a join (select count(1) as count, sum(money) as money,balance-money as balance1 ,帐户表_id from 帐户表_流水表 where id > 1386401935 and balance is not NULL group by 帐户表_id limit 111000)  tt on a.id=tt.帐户表_id and tt.count >1 and tt.balance1+money !=a.balance ;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值