有uuid,ID等字段,ID有12个字符,前6个为地址码,如何根据ID的前6个字符进行分组;
select count(uuid) from a1 group by ??????????

解决方案 »

  1.   

    不知道MySQL有没有substr函数?
      

  2.   

    select count(uuid) from a1 group by substring(id,1,6)
      

  3.   

    可以使用MySQL的SUBSTR函数http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substr#SUBSTR(str,pos), SUBSTR(str FROM pos), SUBSTR(str,pos,len), SUBSTR(str FROM pos FOR len)SUBSTR() is a synonym for SUBSTRING().
    #SUBSTRING(str,pos), SUBSTRING(str FROM pos), SUBSTRING(str,pos,len), SUBSTRING(str FROM pos FOR len)