我不是 DBA 或......但我只是对编写查询非常感兴趣,比如学习它的技巧......现在我问自己这个问题:
How can I get
n
rows frominformation_Schema
from each of databases? (Without knowing the number of databases)
例如......我们有3个数据库((information_Schema,stack,overflow) 我们不知道。
我想从每个数据库中获取 20 个表。我该怎么做?
还有一件事......请不要给我程序。
最佳答案
您可以使用以下内容来实现您想要的:
set @schema_name='';
set @num=0;
select table_schema, table_name FROM (
select
table_schema,
table_name,
@num := if(@schema_name = table_schema, @num + 1, 1) as dummy_1,
@schema_name := table_schema as dummy_2,
@num as row_number
from information_schema.tables
group by table_schema, table_name
having row_number <= 20) A ;
关于mysql - 如何从每个数据库(MySQL)的 information_Schema 中获取 n 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34251273/