service
String itemChildString = "f_ia,f_ib,f_ic";
String day = "2023-08-02";
String meterId= "A010101";
List<LinkedHashMap<String, Object>> mapList = statisticalTargetMapper.getThirdData(itemChildString,day,meterId);
xml
select h.f_collecttime,${itemChildString}
from (select * from t_meterhisvalue where (f_collecttime >= #{day}
and f_collecttime < DATE_ADD(#{day},INTERVAL 1 day))
and f_meterid = #{meterId}) h
LEFT JOIN (select * from t_metersundryvalue where (f_collecttime >= #{day}
and f_collecttime < DATE_ADD(#{day},INTERVAL 1 day)) and f_meterid = #{meterId}) s
on h.f_collecttime = s.f_collecttime and h.f_meterid = s.f_meterid
LEFT JOIN (select * from t_meterthdvalue where (f_collecttime >= #{day}
and f_collecttime < DATE_ADD(#{day},INTERVAL 1 day)) and f_meterid = #{meterId}) t
on h.f_collecttime = t.f_collecttime and h.f_meterid = t.f_meterid
总结
动态用${}占位符 ,例如动态查数据库select * from ${table},table为传来的值。