计算表中每一列的非空值
我正在寻找数据迁移项目中丢失的数据,这份报告将对我有很大帮助。
给定一个 MySQL 表,我想计算该表每一行中的所有空(NULL 或 '')值。输出将是列名称列表以及每列的空行或非空行计数。我会手动将这些数据与源表进行比较 - 手动是因为我预计很少有计数能够完全匹配,并且源表和导入表之间的列名称完全不同。
我有大约 30 个表需要检查,其中一些有 100 列。我可以从 PC 直接访问 MySQL,但无法在带有数据库的服务器上运行任何脚本。
TableA 的示例
Col1 Col2 Col3
'XX' NULL 'XX'
'XX' NULL ''
'XX' 'XX' 'XX'
'XX' '' 'XX'
我想要的报告是(对于带有 '' 的非空计数计为空):
Col1: 4
Col2: 1
Col3: 3
I am looking for missing data in a data migration project, and this report will help me immensely.
Given a MySQL table, I would like to count all the empty (NULL or '') values in each row of that table. The output would be a list of column names and a count of empty or non-empty rows for each column. This data is something I would manually compare to the source tables - manually because I expect few counts to match up exactly and column names are completely different between the source and imported tables.
I have about 30 tables to check, a few with 100 columns. I have direct MySQL access from my PC, but no access to run any scripts on the server with the database.
Example for TableA
Col1 Col2 Col3
'XX' NULL 'XX'
'XX' NULL ''
'XX' 'XX' 'XX'
'XX' '' 'XX'
The report I would want is (for non-empty counts with '' counted as empty):
Col1: 4
Col2: 1
Col3: 3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
COUNT
也会对空字符串进行计数,因此您的查询应如下所示:COUNT
counts empty strings too, so your query should look like this:您可以对每个表使用以下查询
要获取特定表的所有列,您应该运行查询
此查询的结果,您可以将其用于自动生成查询,如第一个查询。
You can use the following query for each table
For getting all columns for a specific table you should run query
Results of this query you can use for auto generation queries like the first one.
仅计算具有值的行(跳过 Null/空行)!!!
Count rows only which has values (Skipping Null/Empty rows)!!!
这对我有用
this worked for me