sql - 仅将非空值插入 SQL 表
问题描述
我尝试将值插入到我的表中,但我只想插入非空值,我需要忽略的空值不需要处理。我要插入的变量是 SQL 选择的结果,我试过了,但没有用:
insert into mytable(id)
values (case when (select id from tab2 where login=?) is not null then (select id from tab2 where login=?))
换句话说,我想插入与此条件相对应且不仅为空的 id。
解决方案
这是你如何做到的:
insert into mytable(id)
select id from tab2
where login=? and id is not null
推荐阅读
- mysql - 它只返回一行。如果我使用 group by 它会给我错误的输出
- reactjs - 用酶测试连接的组件
- css - 使用 flexbox 和 svg(使用 Sandbox)反应星级组件
- excel - 循环退出问题
- python - 对齐表面法线向量的算法
- java - JFrame 不会处理执行的按钮操作
- sybase - SQL Anywhere if..elseif..else 语法错误
- php - 如何将 Wordpress 的“nav_menu_link_attributes”添加到特定菜单?
- python - 如何从装饰器装饰的函数中访问在装饰器中声明的日志记录对象?
- powershell - 从文件夹复制项目并将日期附加到文件名。修改后文件不会关闭