Apol1oBelvedere
V2EX  ›  数据库

如何查询出全部记录中该字段的值全为空的字段?

  •  
  •   Apol1oBelvedere · Apr 20, 2022 · 1783 views
    This topic created in 1490 days ago, the information mentioned may be changed or developed.
    如何查询出全部记录中该字段的值全为空的字段?
    数据库中字段较多,希望简化显示,如果某个字段下全部记录的该字段值都是空值,则不显示该字段。
    如何在数据表中查询出全部这种字段?
    4 replies    2022-04-23 21:07:48 +08:00
    pennai
        1
    pennai  
       Apr 21, 2022
    jdbc 有获取表元数据的 api ,遍历元数据里的每一列,查那列为 null 的 count
    zxyroy
        2
    zxyroy  
       Apr 21, 2022
    COUNT(1) as total, SUM(CASE IF A IS NULL 1 ELSE 0) 然后看看哪些字段等于 total
    0ray
        3
    0ray  
       Apr 21, 2022   ❤️ 1
    这个问题,我硬是没读明白
    Apol1oBelvedere
        4
    Apol1oBelvedere  
    OP
       Apr 23, 2022
    @zxyroy 方法找到:
    1.先用 select column_name from information_schema.Columns 查询出所有字段名;//此语句原样执行;
    2.再用 select count(column1) as column1 from table_name where len(column1) <> '';查询字段下不含字符串的记录数,即可将记录数为零的字段筛选出来。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1122 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 23:00 · PVG 07:00 · LAX 16:00 · JFK 19:00
    ♥ Do have faith in what you're doing.