巧用sql计算累计值

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cd18333612683/article/details/79765350

业务:如下图所示,下图是每日公司故障数和行车里程数统计,要得到累计故障率的数据,举个例子,我想要看3月4日的累计故障率,就要将这天之前所有的故障数加起来,除以里程数之和,得到这一天的累计故障率
这里写图片描述

套用的累计sql:

select id,time,(select SUM(X)from table as i where i.time<=o.time) as total from table as o

这里写图片描述

猜你喜欢

转载自blog.csdn.net/cd18333612683/article/details/79765350