yxwzaxns
V2EX  ›  问与答

没有思路,跪求一段 sql 语句

  •  
  •   yxwzaxns · Nov 5, 2015 · 2177 views
    This topic created in 3856 days ago, the information mentioned may be changed or developed.

    mysql db user 表
    int id,
    field1 char,
    field2 char,
    field3 char,
    ......
    假设我现在只知道这张表里有字段 id ,现在我想查询出表里内容为 null 的
    字段所对应的字段名 fiels 和 id 号,

    现在我只想到先查询表的所有字段,在循环查询得出结果这个办法,

    有没有其他快捷的办法呢

    5 replies    2015-11-06 10:22:23 +08:00
    id4alex
        1
    id4alex  
       Nov 5, 2015
    ---现在我想查询出表里内容为 null 的
    select * from user where id not in (select id from user where field1 is not null and field2 is not null .... and fieldn is not null)
    yxwzaxns
        2
    yxwzaxns  
    OP
       Nov 5, 2015
    @id4alex 汗,我已经假设我不知道表里的字段名了
    heaton_nobu
        3
    heaton_nobu  
       Nov 5, 2015
    show columns from user
    msg7086
        4
    msg7086  
       Nov 6, 2015
    字段名也可以去 information_schema 找
    id4alex
        5
    id4alex  
       Nov 6, 2015
    @yxwzaxns 用 shell 来拼接 sql 来做吧
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5287 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 07:45 · PVG 15:45 · LAX 00:45 · JFK 03:45
    ♥ Do have faith in what you're doing.