上方选择日期,下面显示所选月的数据。
新需求是新增一个弹框,点击之后展示日期选择器所选年的1-12月的数据变化曲线。
数据库用varchar存的日期(202202),我的想法是在代码里截图前台传的日期("202112")中的年份,然后再拼接字符串 “2021”+“01” “2021”+“12”
传给sql语句 俩个值 查询出来1-12月的数据。
但是我感觉这样有点麻烦了,sql有没有能实现这种需求的语法呢 ? MySql5.7
public List<Map<String, Object>> selectFullPersonAllMonth(String yearMonth) {
String year = yearMonth.substring(0, 4);
String start = year +"01"; //start
String end = year +"12"; //end
return sdRecruitAndUseMapper.selectFullPersonAllMonth(start,end);
}
SELECT ifnull(bpf.full_person_count, 0) full_person_count,
substring(bpf.`year_month`, 5, 2) AS month
FROM sddp.bigping_person_full bpf
WHERE bpf.org_id = '36808'
AND bpf.`year_month` BETWEEN #{start} AND #{end}
ORDER BY bpf.`year_month`
传年份,然后like这个年份可以吗 比如:bpf.year_month
like substr(#{date},1,4) || '%'
https://www.cnblogs.com/dshore123/p/7813230.html
sql 里instr()函数直接截取年份或月份,然后聚合函数count()查询
一条sql就可以查出来
where left(数据库时间字段,4) =${year}