2017-06-06 77 views
0

下面的配置单元查询花费了无限长的执行时间(超过3天)。不确定查询中的任何优化是否有帮助。配置单元查询花费无限多的时间执行

任何建议表示赞赏!

select count(distinct(a.custname)) from (
    (select custname, pages, variable 
    from table1 
    where date_time between "2017-01-01" and "2017-01-31" 
    and (pages in ('Summary', 'Details') 
    or variable in ('Complete', 'Receive'))) a 
    left join 
    (select custname, pages, variable 
    from table1 
    where date_time between "2017-01-01 00:00:00" and "2017-01-31 00:00:00" 
    and (pages not in ('Summary', 'Details') 
    and variable not in ('Complete', 'Receive'))) b 
    on a.custname = b.custname) 
    where b.pages is null 
+0

哟使用变体数据格式DATE_TIME。什么是列类型,如果是字符串什么是真正的格式? –

回答

0
select count(*) 

from (select  custname 

     from  table1 

     where  date_time between date '2017-01-01' and date '2017-01-31' 

     group by custname 

     having  count 
        (
         case 
          when pages  in ('Summary' ,'Details') 
           or variable in ('Complete','Receive') 
          then 1 
         end 
        ) > 0 

       and count 
        (
         case 
          when pages not in ('Summary' ,'Details') 
           and variable not in ('Complete' ,'Receive') 
          then 1 
         end 
        ) = 0 
     ) t