mysql> select floor(rand(1)*2) a from information_schema.tables group by a having count(*)>1;
+---+
| a |
+---+
| 0 |
| 1 |
+---+
2 rows in set (0.00 sec)mysql> select floor(rand(0)*2) a from information_schema.tables group by a having count(*)>1;
ERROR 1062 (23000): Duplicate entry '1' for key 'group_key'这两个sql语句就rand()的种子数0,1 不一样,为啥会出现这种情况

解决方案 »

  1.   

    汗 真心没看懂这sql是什么意思
      

  2.   

    SELECT FLOOR(RAND(1)*2) a FROM information_schema.TABLES GROUP BY a HAVING COUNT(*)>1;
    mysql 5.1.32下测试没有问题
      

  3.   

    我知道这没问题,但是如果换成 rand(0) 就出现问题了,你没仔细看我的问题
      

  4.   

    SELECT a,COUNT(*) FROM (
    SELECT FLOOR(RAND(0)*2) a FROM information_schema.TABLES) a1 GROUP BY a HAVING COUNT(*)>1;;
    mysql 5.1.32下测试没有问题
      

  5.   

    参考一下:
    http://bugs.mysql.com/bug.php?id=32249
      

  6.   

    谢谢,非常感谢,大哥,你的QQ是啥,以后有问题直接向你请假了!!~~为了这个问题,我纠结了n久了