获取当前月份用电量
select IFNULL(sum(use_energy), 0) as useEnergy
from meter_records_hours
where DATE_FORMAT(record_date, '%Y%m') = DATE_FORMAT(CURDATE(), '%Y%m')
and corpid = #{corpid}
得到当前月上一个月用电量
SELECT IFNULL(sum(use_energy), 0) as useEnergy
FROM meter_records_month
WHERE PERIOD_DIFF(date_format(now(), '%Y%m'), date_format(record_date, '%Y%m')) = 1
and corpid = #{corpid}
mybatis中list集合非空校验
<if test="null != macs and macs.size > 0">
and mac in
<foreach collection="macs" open="(" separator="," close=")" item="mac" index="i">
#{mac}
</foreach>
</if>
mysql数据格式化问题
date_format(record_date, '%Y-%m-%d')
date_format(record_date, '%Y-%m')
date_format(record_date, '%Y-%m-%d %H:%i')
group by 可多个分组
group by record_date,mac