我用java代码取某个字段的值比较,发现和sql  (select email from user group by email having count(*)>1)
结果不一致。
select email from user group by email having count(*)>1 出来的结果是 大小写不分的。 比如v  和V  他统计的时候认为是同一个值。
而java的map统计迭代处理要细致很多。有没有什么方法可以让select email from user group by email having count(*)>1   区分大小写?

解决方案 »

  1.   

    select BINARY email from user group by email having count(*)>1
      

  2.   

    应该是group by 里面放binary,否则group by的时候还是不区分大小写的。select的时候因为group by的时候已经区分了,就没有必要再binary一下了。
      

  3.   

    select  email from user group by binary email having count(*)>1这个是正确的    
      

  4.   

    select BINARY email from user group by BINARY email having count(*)>1
      

  5.   

    BINARY不是函数,是类型转换运算符,它用来强制它后面的字符串为一个二进制字符串,可以理解为在字符串比较的时候区分大小写。处理方法:
    1、最好在存储时就区分大小写,否则有中文时会出问题。
    建表时:email varchar(64) BINARY NOT NULL default ''
    2、查询时:select email from user group by BINARY email having count(*)>1