当前位置:   article > 正文

sql语句计算当月的月累计_sql 每月累计

sql 每月累计

 select                           
sum(cast(ZL_Dian as real)) as ZL_Dian,
sum(cast(JLB as real)) as JLB
from  ENERGY_BOF_DayReport  where(riqi between dateadd(month, datediff(month, 0, getdate()), 0)   and   format(DATEADD(DAY, -1, GETDATE()),'yyyy-MM-dd') 

//红色的代表本月第一天时间

//棕色代表当天的时间

//用到了between and 计算日期区间的函数

//sum为累计函数

需要注意数据库的格式,笔者这里的数据库的格式都为varchar所以在这里用到了cast()as real

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/950285
推荐阅读
相关标签
  

闽ICP备14008679号