2017-02-14 41 views
0

У меня есть запрос со многими заявлениями случаеMySQL- оптимизирует

SELECT 
    case when (std_no like '070%' or std_no like '071%') then 'A' 
    when (std_no like '077%' or std_no like '076%') then 'B' 
    when std_no like '075%' then 'C' 
    when std_no like '072%' then 'D' 
    when std_no like '078%' then 'E' 
    when (std_no not like '07%' and std_no not like '00%' 
     and std_no not like '0100%' 
     and substring(std_no,4,1) in('2','3')) then 'F' 
    when (std_no not like '07%' and std_no not like '00%' 
     and std_no not like '0100%' 
     and substring(std_no,4,1)='5') then 'G' 
    when (std_no not like '07%' and std_no not like '00%' 
     and std_no not like '0100%' 
     and substring(std_no,4,1)='7') then 'H' 
    end as GroupName,city_id, 
    count(*) as PostCount 
    from imei_tb 
    where reg_date>='2017-01-06' 
    and reg_date<='2017-01-10' 
    and length(std_no)='10' 
    GROUP BY GroupName,city_id 
    ORDER BY city_id ASC 

Есть ли решение, чтобы сделать этот запрос скорость вверх? Заранее спасибо

+0

Предоставить вывод 'SHOW CREATE TABLE imei_tb' –

ответ

1

`ИНДЕКС (reg_date), вероятно, является единственным полезным индексом.

Вы должны сделать 2 вида - один для GROUP BY, другой для ORDER BY.

Как только я вижу SHOW CREATE TABLE imei_tb, я думаю, что смогу дать вам улучшенный запрос, используя подзапрос.

 Смежные вопросы

  • Нет связанных вопросов^_^