我有很多案例陈述的查询

    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


有什么解决方案可以加快查询速度吗?
提前致谢

最佳答案

`INDEX(reg_date)可能是唯一有用的索引。

您被迫进行2种排序-一种用于GROUP BY,另一种用于ORDER BY

看到SHOW CREATE TABLE imei_tb后,我认为我可以使用子查询为您提供改进的查询。

关于mysql - MySQL-优化案例陈述,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42224718/

10-11 02:17