帮我优化下面的sql,运行很多个小时 数据库:sybase
select
too.toID,too.toName,frm.fromID,frm.fromName<br>
from
entityClientTempTable frm, entityClientTempTable too
where
frm.fromServerId = too.toServerId
and
frm.fromID < too.toID
and
lower(substring(frm.fromName, 0, CHARINDEX(''------'',frm.fromName))) like lower(too.toName))
entityClientTempTable中的记录数:约五十万 entityClientTempTable表上没有索引 entityClientTempTable是一个临时表。
答案 0 :(得分:0)
请你试试这个:
select too.toID,too.toName,frm.fromID,frm.fromName
from entityClientTempTable frm
inner join entityClientTempTable too on frm.fromServerId = too.toServerId
and frm.fromID < too.toID
where lower(substring(frm.fromName, 0, CHARINDEX(''------'',frm.fromName))) like lower(too.toName))