select t.table_name from information_schema.tables t
left join information_schema.columns c
on c.table_name = t.table_name
and c.table_schema = t.table_schema
where t.table_schema = 'test'
and count(c.column_name) = max(count(c.column_name))
我试图从数据库“test”中选择具有最高列数的表.但是,我无法做到这一点.我也尝试选择count(c.column_name),但不是返回每个表的列数,而是返回最大列数.
如何选择列数最多的表?
最佳答案
尝试按表名分组.就像是:
原文链接:https://www.f2er.com/mysql/433191.htmlSELECT TABLE_NAME,COUNT(*) as c
FROM INFORMATION_SCHEMA.COLUMNS
GROUP BY TABLE_NAME
ORDER BY c desc
LIMIT 1;