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

2015-11-05 19:52:40 +08:00
 yxwzaxns

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

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

有没有其他快捷的办法呢

1709 次点击
所在节点    问与答
5 条回复
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
2015-11-05 22:27:04 +08:00
@id4alex 汗,我已经假设我不知道表里的字段名了
heaton_nobu
2015-11-05 22:47:00 +08:00
show columns from user
msg7086
2015-11-06 04:35:17 +08:00
字段名也可以去 information_schema 找
id4alex
2015-11-06 10:22:23 +08:00
@yxwzaxns 用 shell 来拼接 sql 来做吧

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/233949

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX