mysql dynamic table query

Dynamically join table query, I don't know how many tables there are

Insert picture description here

Here tables is a list collection

![“gps_warn_data_202001”,“gps_warn_data_202002”,“gps_warn_data_202003”,“gps_warn_data_202004”,“gps_warn_data_202005”]在这里插入图片描述
Insert picture description here


union all

select
vi.VH_CODE ‘vhCode’ ,
da.CHINA_NAME ‘chinaName’,
alarmType.DICT_DESC ‘warnType’,
date_format(gwd.START_TIME, ‘%y-%m-%d %h:%i:%s’) ‘startTime’,
case when PROCESS_USER is null then ‘未处理’ else ‘已处理’ end ‘processResult’
from
${item} gwd
JOIN
vehicle_info vi ON gwd.VH_GUID = vi.VH_GUID
LEFT JOIN
driver_acceptance da ON da.CARD_FIX_NO = gwd.CARD_FIX_NO
JOIN
(select DICT_CODE,DICT_DESC from info_ge_dict where TYPE_CODE = ‘ALARM_TYPE’ and DICT_CODE not in(‘1’,‘2’,‘3’)) alarmType on alarmType.DICT_CODE = gwd.WARN_TYPE

	</foreach>

Use case when then else end to determine the empty string

Insert picture description here
Insert picture description here
Insert picture description here

Manually query the serial number

Insert picture description here

Last order

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_26634873/article/details/106429766