我ACCOUNT的结构表如下:
ACCOUNT_ID | ACCOUNT_STATUS|
004460721 | 2 |
042056291 | 5 |
601272065 | 3 |
Run Code Online (Sandbox Code Playgroud)
我需要使用一个SELECT语句一次更新三行,这样第二列将分别为5,3,2.
我使用了以下查询,但似乎缺少了一些东西
UPDATE ACCOUNT
SET ACCOUNT_STATUS = CASE
WHEN ACCOUNT_STATUS = '004460721' THEN 5
WHEN ACCOUNT_STATUS = '042056291' THEN 3
WHEN ACCOUNT_STATUS = '601272065' THEN 2
WHERE ACCOUNT_ID IN ('004460721','042056291','601272065')
Run Code Online (Sandbox Code Playgroud)
我的问题,这种方式是否正确?如果不是,我可以使用声明吗?CASE WHEN我SUB-SELECT在一个声明中如何选择使用声明?
请注意这是为了SQL ORACLE
好的,基于你给我的小提琴,我尝试过这些,它对我有用
create table account( account_id number primary key,
account_status varchar2(30));
insert into account values(1, '5');
insert into account values(2, '3');
insert into account values(3, '2');
select * from account
update account
set account_status= case
when account_id=1 then '2'
when account_id=2 then '5'
when account_id=3 then '3'
END
select * from account
Run Code Online (Sandbox Code Playgroud)
我没有使用where条件
| 归档时间: |
|
| 查看次数: |
62350 次 |
| 最近记录: |