TIMESTAMPDIFF(DAY, ddf.created_date, ddf.updated_date) AS diffDayTime,
TIMESTAMPDIFF(MINUTE, ddf.created_date, ddf.updated_date) AS diffMinuteTime,
tdf.`status` AS freqStatus,
LEFT(tdf.created_date, 19) AS freqTime,
tdf.freq_type AS freqType,
TIMESTAMPDIFF(DAY, tdf.created_date, tdf.updated_date) AS diffDayTime,
TIMESTAMPDIFF(MINUTE, tdf.created_date, tdf.updated_date) AS diffMinuteTime,
tdp.soc AS batteryLevel,
ddf.catching_timer AS catchingTimer,
ddf.timer AS timer,
ddf.`week` AS `week`,
ddf.week_timer AS weekTimer,
tdf.catching_timer AS catchingTimer,
tdf.timer AS timer,
tdf.`week` AS `week`,
tdf.week_timer AS weekTimer,
tv.created_by createdBy,
tu2.username,
IF(ddf.user_type = 1, tu.username, tcula.username) AS operation
tdf.user_type AS userType,
tdf.created_by AS freqCreatedBy
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_workorder tw on tw.id = tv.workorder_id
left join t_device td on td.sn = tvd.sn
left join t_device_location tdl on tdl.sn = tvd.sn
left join t_device_power tdp on tdp.sn = tvd.sn and tvd.id = tdp.vd_id
left join (select * from (SELECT * FROM t_device_freq order by created_date desc) temp GROUP BY temp.sn) ddf on ddf.vehicle_id = tv.id and ddf.sn = td.sn
left join t_user tu on tu.id = ddf.created_by
left join t_cust_user_auth_rel tcuar on tcuar.user_id = ddf.created_by and tcuar.auth_type = 'local'
left join t_cust_user_local_account tcula on tcula.auth_id = tcuar.auth_id
left join (select * from (select * from t_device_freq order by created_date desc) temp group by temp.sn) tdf on tdf.vehicle_id = tv.id and tdf.sn = td.sn