V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
yxwzaxns
V2EX  ›  问与答

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

  •  
  •   yxwzaxns · 2015 年 11 月 5 日 · 2075 次点击
    这是一个创建于 3808 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

    有没有其他快捷的办法呢

    5 条回复    2015-11-06 10:22:23 +08:00
    id4alex
        1
    id4alex  
       2015 年 11 月 5 日
    ---现在我想查询出表里内容为 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
       2015 年 11 月 5 日
    @id4alex 汗,我已经假设我不知道表里的字段名了
    heaton_nobu
        3
    heaton_nobu  
       2015 年 11 月 5 日
    show columns from user
    msg7086
        4
    msg7086  
       2015 年 11 月 6 日
    字段名也可以去 information_schema 找
    id4alex
        5
    id4alex  
       2015 年 11 月 6 日
    @yxwzaxns 用 shell 来拼接 sql 来做吧
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   5784 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 06:20 · PVG 14:20 · LAX 23:20 · JFK 02:20
    ♥ Do have faith in what you're doing.