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

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

  •  
  •   yxwzaxns · 2015-11-05 19:52:40 +08:00 · 1701 次点击
    这是一个创建于 3110 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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-05 22:21:22 +08:00
    ---现在我想查询出表里内容为 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-05 22:27:04 +08:00
    @id4alex 汗,我已经假设我不知道表里的字段名了
    heaton_nobu
        3
    heaton_nobu  
       2015-11-05 22:47:00 +08:00
    show columns from user
    msg7086
        4
    msg7086  
       2015-11-06 04:35:17 +08:00
    字段名也可以去 information_schema 找
    id4alex
        5
    id4alex  
       2015-11-06 10:22:23 +08:00
    @yxwzaxns 用 shell 来拼接 sql 来做吧
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1124 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:54 · PVG 02:54 · LAX 11:54 · JFK 14:54
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.