从表A模糊查询出结果,能够再B表按条件查询出的结构中找到的数据
下面是sql语句:
select t1.showCode, t1.Name, t1.Sex, t.AppointmentDate from (select *from A where AppointmentDate >= date_sub(current_date(), interval '10' day) and isFinish = 0 ) t
inner join (select *from B where (Name = '%1111%' or showCode like '%1111%') and HospitalID = '20220302160409') t1 on t.PatientID = t1.PatientID order by t.AppointmentDate desc;
这样在结尾加上 order by t.AppointmentDate desc排序语句就变得非常慢,比不加排序语句相差几十倍,请问要如何优化啊?
补充下explain结果如图: