在mysql里执行select 1 from (select count(*),concat(floor(rand(0)*2),(select table_name from information_schema.tables where table_schema='mysql' limit 0,1))a from information_schema.tables group by a)b;这句话,为什么会出错,错误信息是:ERROR 1062 (23000): Duplicate entry '1columns_priv' for key 1,到网上查了下Duplicate entry,貌似是主键重复还是什么的,但还是不太懂,有人能解释下吗?先谢谢了。
我的mysql是5.0.51b-community-nt-log版本的
我看了下,没有什么问题啊。我重新安装的mysql执行这个语句也会出错的
SQL的关键错在最后一个from information_schema.tables, 它会枚举所有的行。要以尝试下边这个:
select 1 from
(
select count(*), (concat(floor(rand(0)*2),
( select table_name from information_schema.tables where table_schema='mysql' limit 0,1)
) ) as a
from (select 0) c group by a
) b
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)