当前位置: 代码迷 >> Sql Server >> SQL 语句很慢。该怎么解决
  详细解决方案

SQL 语句很慢。该怎么解决

热度:14   发布时间:2016-04-27 18:01:32.0
SQL 语句很慢。
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多万条数据吧。
这个语句怎么优化一下?

------解决方案--------------------
探讨

如果没有办法的话 我就至于试试分开了 多写点代码。。 对SQL 真的很业余.
  相关解决方案