请问这样的语句该如何优化,本地执行就需要10秒,总共约100万数据
这里我举例说明我的需求,实际情况字段要比下面的多好多。
人员表:t_person
personid int, //主键,人员IDname varchar(32) //人员姓名
id int, //主键,自增personid int,//人员IDstatus tinyint,//考试状态 0:未通过 1:通过examdate datetime//考试日期
id int, //主键,自增personid int,//人员IDstatus tinyint,//考试状态 0:未通过 1:通过examdate datetime//考试日期
select * from v_km12 a where not exists (select personid from t_km1 where personid=a.personid and status=1 and exists (select personid from t_km2 where personid=a.personid and status=1))
with table as( select personid from t_km1 where status = 0 union select personid from t_km2 where status = 0 )select * from t_Personinner join table on table.personid = t_Person.personid