2017-06-06 97 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