表内数据
由数据可以看出每个相同的vin码有两条或者更多条数据,由于业务需求无法横向落库,但是展示的时候要求横向展示,如下图所示
此时我们就需要在sql中做一些处理
select car_code, car_value, tail_time,
<foreach item="code" collection="paramCode" open="" separator="," close="">
MAX(CASE tail_code WHEN #{code} THEN tail_info ELSE '--' END) as #{code}
</foreach>
from tail_record
GROUP BY uuid,tail_time
tail_code为配置表中配置数据,所以我传了一个list 使用case when函数实现该效果