社区
疑难问题
帖子详情
“update 表A set 字段X='yy' where a=1”语句怎样加入这样的判断?
snailili
2003-10-30 04:54:42
就是一个类似条件选择的判断:
当a=1时执行字段X='yy' ;
当b=2时执行字段Q='pp';
能否用一个SQL语句就把它搞定,就象case......when...then...一样
因为有十个左右的判断更新,我不想逐个在查询分析器去写,执行
谢谢!
...全文
31
10
打赏
收藏
“update 表A set 字段X='yy' where a=1”语句怎样加入这样的判断?
就是一个类似条件选择的判断: 当a=1时执行字段X='yy' ; 当b=2时执行字段Q='pp'; 能否用一个SQL语句就把它搞定,就象case......when...then...一样 因为有十个左右的判断更新,我不想逐个在查询分析器去写,执行 谢谢!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
10 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
zjcxc
2003-10-30
打赏
举报
回复
update 表 set x=case when a=1 then 'yy' else x end,Q=case when b=2 then 'pp' else Q end
DigJim
2003-10-30
打赏
举报
回复
declare @a int
declare @b int
declare @X varchar(12)
declare @Q varchar(12)
set @a=1
set @b=1
select case when @a=1 then @X='YY' when @b=2 then @Q='pp' end
DigJim
2003-10-30
打赏
举报
回复
declare @a int
declare @b int
declare @X varchar(12)
declare @Q varchar(12)
set @a=1
set @b=1
case when @a=1 then @X='YY' when @b=2 then @Q='pp' end
lvltt
2003-10-30
打赏
举报
回复
类似这样:
(case when a=1 then X='yy' else '' end)
(case when b=2 then Q='pp' else '' end)
txlicenhe
2003-10-30
打赏
举报
回复
好象只能如上用 case when 了
否则用if语句分好几两来写更麻烦。
pbsql
2003-10-30
打赏
举报
回复
用n个SQL语句把它搞定:
update 表A set 字段X='yy' where a=1
update 表A set 字段Q='pp' where b=2
...
pengdali
2003-10-30
打赏
举报
回复
提高效率:
update 表 set x=case when a=1 then 'yy' else x end,Q=case when b=2 then 'pp' else Q end where a=1 or b=2
pengdali
2003-10-30
打赏
举报
回复
update 表 set x=case when a=1 then 'yy' else x end,Q=case when b=2 then 'pp' else Q end
zarge
2003-10-30
打赏
举报
回复
笔误
update 表
set x = case when a = 1 then 'yy' else x end,
q = case when b = 2 then 'pp' else q end
zarge
2003-10-30
打赏
举报
回复
update 表
set x = case when a = 1 then 'yy' else x end,
y = case when b = 2 then 'pp' else y end
update
数据
表
set
字段
1=
字段
1+id的sql
语句
公式:
update
tbname
set
字段
1=concat(
字段
1,id); 实例: 比如先建一个varchar(10)型
字段
名为sbname,填上字符型内容 'sb',然后通过缀加ID号的方式,给
字段
的值改变为sb1,sb2,sb3,编码与ID号保持一致。 命令如下:
UPDATE
`
表
名`
SET
`sbname`='sb';
update
表
名
set
`sbname`=...
MySQL
update
A
set
num=num+ ? where id=?是否存在并发的问题
在我们的实际开发中,往往会遇到更新数据
字段
的问题。如投票时,如果多人同时投票,是否存在在取数据并更新的时候,原始值是相同的,而后续的
update
操作会造成错误的数据? 比如,
表
名A,
字段
名为 number,如下的SQL
语句
:
语句
1:
update
A
set
number=number+ 5 where id=1;
语句
2:
update
A
set
number=number+ 7 where...
sql的
update
语句
批量更新某
字段
Mysql: 1 有时候要实现
字段
的批量替换
update
表
名
set
字段
A = replace(
字段
A ,"png","jpg" ); 2 批量拼接字符串到某
字段
update
表
名
set
字段
A = CONCAT(
字段
A , "xxx" );
update
表
名
set
字段
A = CONCAT( "
yy
y" ,
字段
A , "xxx" ); 3 批量截...
讨论
update
A
set
number=number+ ? where id=?的原子性 (含数据库原理)
结论:1. 本句本身具有原子性2. 当前读(包含
update
等写入操作)锁定数据,直到事务提交https://www.zhihu.com/question/46733729/answer/128582074阿里的mysql大咖给出了肯定的答案比如,
表
名A,
字段
名为 number,如下的SQL
语句
:
语句
1:
update
A
set
number=number+ 5 where id=1;
语句
2...
sql更新
语句
中
update
set
from用法
执行一般的sql更新
语句
为
update
table_name
set
column_name=value where column_name1=value1;但是我们有时候需要将某个
表
用的
字段
根据两个
表
中相关
字段
更新为另一个
表
中某个
字段
的数据,即a
表
中主键aid在b
表
中有个外键bid相关,b
表
中
字段
b需要根据a、b
表
对应id更新为a
表
中
字段
c的数据,如果根据以上的sql一条一条的更...
疑难问题
22,207
社区成员
121,730
社区内容
发帖
与我相关
我的任务
疑难问题
MS-SQL Server 疑难问题
复制链接
扫一扫
分享
社区描述
MS-SQL Server 疑难问题
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章