加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

MySQL选择列数最多的表?

发布时间:2020-12-11 23:46:28 所属栏目:MySql教程 来源:网络整理
导读:select t.table_name from information_schema.tables tleft join information_schema.columns con c.table_name = t.table_nameand c.table_schema = t.table_schemawhere t.table_schema = 'test'and count(c.column_name) = max(count(c.column_name)) 我

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),但不是返回每个表的列数,而是返回最大列数.

如何选择列数最多的表?

最佳答案 尝试按表名分组.就像是:

SELECT TABLE_NAME,COUNT(*) as c
FROM INFORMATION_SCHEMA.COLUMNS
GROUP BY TABLE_NAME
ORDER BY c desc
LIMIT 1;

Fiddle

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读