- SQL code
SELECT *, ( CASE com.company_type WHEN '1' THEN (SELECT name, FROM sgperson WHERE id = com.person_id) WHEN '2' THEN (SELECT name FROM jlperson WHERE id = com.person_id) WHEN '3' THEN (SELECT name FROM jcperson WHERE id = com.person_id) WHEN '5' THEN (SELECT name FROM sjperson WHERE id = com.person_id) END ) pic, ( CASE com.company_type WHEN '1' THEN (SELECT tel1 FROM sgperson WHERE id = com.person_id) WHEN '2' THEN (SELECT tel1 FROM jlperson WHERE id = com.person_id) WHEN '4' THEN (SELECT tel1 FROM jcperson WHERE id = com.person_id) WHEN '5' THEN (SELECT tel1 FROM sjperson WHERE id = com.person_id) END ) tel1, ( CASE com.company_type WHEN '1' THEN (SELECT tel2 FROM sgperson WHERE id = com.person_id) WHEN '2' THEN (SELECT tel2 FROM jlperson WHERE id = com.person_id) WHEN '4' THEN (SELECT tel2 FROM jcperson WHERE id = com.person_id) WHEN '5' THEN (SELECT tel2 FROM sjperson WHERE id = com.person_id) END ) tel2FROM com_project com, userg [user]WHERE project_id = 'AA325552' AND deptid = company_id AND com.attend_id LIKE '%,KT365688,%'
SQLSERVER2008 这条语句执行时间是8秒,而且在一次查询中这条语句还会指定多次,造成了页面半天都打不开。
sgperson、jlperson 这几个表里,现在每个表大概是10多万条数据吧。
这个语句怎么优化一下?
------解决方案--------------------