有时候在做根据年月查询时要用到对时间切割字符串,代码如下:
select of.id, of.name, (select count(ctd.id) from car_train_driver ctd where ctd.done= '1' and ctd.car_train_id in (select id from car_train where parent_id in (select id from car_train where user_id in (select id from sys_user where office_id in (select id from sys_office where parent_id in (select id from sys_office where parent_id = of.id <if test="year !=null and year !=''"> AND DATE_FORMAT(ctd.create_date,"%Y")= #{year} </if> <if test="month != null and month !=''"> AND DATE_FORMAT(ctd.create_date,"%m")=#{month} </if> ) ) ) ) ) ) num, format(if((select (sum(score)/(count(