“统计数据库 Column 列”通常有几种常见含义,下面按不同统计目的给你说明,并给出主流数据库示例(MySQL / PostgreSQL / SQL Server / Oracle)。
SELECT COUNT(*) AS column_count
FROM information_schema.columns
WHERE table_schema = '数据库名'
AND table_name = '表名';
SELECT COUNT(*) AS column_count
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = '表名';
SELECT COUNT(*) AS column_count
FROM information_schema.columns
WHERE table_catalog = '数据库名'
AND table_name = '表名';
SELECT COUNT(*) AS column_count
FROM user_tab_columns
WHERE table_name = '表名';
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name = '表名';
SELECT column_name, data_type
FROM user_tab_columns
WHERE table_name = '表名';
SELECT COUNT(*) AS total_columns
FROM information_schema.columns
WHERE table_schema = '数据库名';
SELECT COUNT(*) AS total_columns
FROM information_schema.columns
WHERE table_schema = 'public';
如果你是想知道 某一列的数据统计(如数量、去重数、空值):
SELECT
COUNT(*) AS 总行数,
COUNT(列名) AS 非空行数,
COUNT(DISTINCT 列名) AS 去重值,
SUM(CASE WHEN 列名 IS NULL THEN 1 ELSE 0 END) AS 空值数
FROM 表名;
COUNT(*) 统计的是行数,不是列数如果你能告诉我:
我可以给你更精确的 SQL。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。