yxwzaxns
V2EX  ›  问与答

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

  •  
  •   yxwzaxns · Nov 5, 2015 · 2497 views
    This topic created in 4025 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
    id4alex
    Nov 5, 2015
    1
    ---现在我想查询出表里内容为 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
    yxwzaxns
    OP
    Nov 5, 2015
    2
    @id4alex 汗,我已经假设我不知道表里的字段名了
    heaton_nobu
    heaton_nobu
    Nov 5, 2015
    3
    show columns from user
    msg7086
    msg7086
    Nov 6, 2015
    4
    字段名也可以去 information_schema 找
    id4alex
    id4alex
    Nov 6, 2015
    5
    @yxwzaxns 用 shell 来拼接 sql 来做吧
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   948 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 19:58 · PVG 03:58 · LAX 11:58 · JFK 14:58
    ♥ Do have faith in what you're doing.