数据库多表共有属性关联查询,按各表时间属性排序
程序员文章站
2022-05-08 11:24:33
...
摘要表p_report_list:
要素表
p_report_videoperson:
p_report_videocar:
p_report_videomac:
p_report_videotext:
查询语句:
select * from (
select person_id as id, patrol_id, location_id, person_picture_url as url, type, person_show_start_time as showtime from p_report_videoperson
union all
select car_id as id, patrol_id, location_id, car_picture_url as url, type, car_show_start_time as showtime from p_report_videocar
union all
select mac_id as id, patrol_id, location_id, mac_picture_url as url, type, mac_show_start_time as showtime from p_report_videomac
union all
select audio_id as id, patrol_id, location_id, audio_picture_url as url, type, audio_show_start_time as showtime from p_report_videotext
) as ref
where patrol_id = '540fa8bfc9e84224af803e8c9c84f4aa'
order by showtime
查询结果: