下面是我的sql  请问还可以怎么优化
select t.tuid,
       s.jobName,
       g.groupName,
       g.groupType,
       e.typeName,
       t.logMessage,
       t.logTime,
       c.descripTion,
       c.code,
       c.codeType,
       c.description        logdetail,
       clogtype.description logtype,
       caction.description  action
  from schedule_log t  left join schedule s
    on (t.jobid = s.tuid)  left join schedule_group g
    on (t.jobgroupid = g.tuid)  left join schedule_group_type e
    on (e.tuid = g.grouptype)  left join schedule_log_code caction
    on (t.action = caction.code and caction.codetype = 1)  left join schedule_log_code clogtype
    on (t.logtype = clogtype.code and clogtype.codetype = 2)  left join schedule_log_code c
    on (t.logdetail = c.code and c.codetype = 3)

解决方案 »

  1.   

    首先可以肯定的是括号可以去掉。。然后就是on后面clogtype.codetype = 2这种关联条件的,要肯定是整行的筛选条件还只是左连接的筛选条件,整行筛选的话要放在where后面。
    至于优化的话,这种基本的查询,我也想看看大神的方案。。
      

  2.   

    这样吗
    select t.tuid,
           s.jobName,
           g.groupName,
           g.groupType,
           e.typeName,
           t.logMessage,
           t.logTime,
           c.descripTion,
           c.code,
           c.codeType,
           c.description        logdetail,
           clogtype.description logtype,
           caction.description  action
      from schedule_log t  left join schedule s
        on t.jobid = s.tuid  left join schedule_group g
        on t.jobgroupid = g.tuid  left join schedule_group_type e
        on e.tuid = g.grouptype  left join schedule_log_code caction
        on t.action = caction.code  left join schedule_log_code clogtype
        on t.logtype = clogtype.code  left join schedule_log_code c
        on t.logdetail = c.code
        where  c.codetype = 3 and clogtype.codetype = 2 and caction.codetype = 1
      

  3.   

    这样吗
    select t.tuid,
           s.jobName,
           g.groupName,
           g.groupType,
           e.typeName,
           t.logMessage,
           t.logTime,
           c.descripTion,
           c.code,
           c.codeType,
           c.description        logdetail,
           clogtype.description logtype,
           caction.description  action
      from schedule_log t  left join schedule s
        on t.jobid = s.tuid  left join schedule_group g
        on t.jobgroupid = g.tuid  left join schedule_group_type e
        on e.tuid = g.grouptype  left join schedule_log_code caction
        on t.action = caction.code  left join schedule_log_code clogtype
        on t.logtype = clogtype.code  left join schedule_log_code c
        on t.logdetail = c.code
        where  c.codetype = 3 and clogtype.codetype = 2 and caction.codetype = 1
    感觉好像更慢了
      

  4.   

    不允许使用存储过程那样改写和原来sql完全不一样啦