在UPDATE巢狀表更新資料

2021-04-13 09:48:33 字數 967 閱讀 3021

分享乙個update語句中使用from的sql語句:

以下例子供大家學習:

bbs表的表結構sql語句:

if exists (select * from dbo.sysobjects where id = object_id(n'[dbo].[bbs]') and objectproperty(id, n'isusertable') = 1)

drop table [dbo].[bbs]

gocreate table [dbo].[bbs] (

[bid] [int] not null ,

[cla_id] [int] null ,

[buser] [nvarchar] (50) collate chinese_prc_ci_as null ,

[sub_id] [int] null ,

[ter_id] [int] null ,

[bresult] [int] null ,

[btype] [int] null ,

[bkcj] [int] null ,

[yxcj] [int] null ,

[zc_flag] [char] (1) collate chinese_prc_ci_as null ,

[bk_flag] [char] (1) collate chinese_prc_ci_as null

) on [primary]

goupdate的sql語句:

update bbs set yxcj=upbbs.updatebbs  from ( select  *,(case when (bresult<60 and (bkcj<60 or bkcj is null)) then null else (case when bresult>=60 then bresult else bkcj end ) end) as updatebbs from bbs) upbbs where bbs.bid=upbbs.bid 

update關聯其他表批量更新資料

批量更新表時,update乙個表的列時,需要依賴另外的表,這種依賴可以是where條件子句,也可以要update的field的值依賴另外的表 通常有兩種做法 1.使用儲存過程 2.在程式 裡逐條迴圈執行 這裡給出一種更高效 簡潔的做法,批量更新sql 一句sql就可以替代麻煩的迴圈過程,有ms sq...

access 資料更新update

1 單錶內字段更新 update pipeline set state 0 where address 33 2 兩個表間關聯更新 在access資料庫中,update指令不能夠含有from語句。因此在多表關聯批量更新資料時操作不是那麼方便。update table1 as t1,table2 as...

mysql大表更新 大表的update更新

因為業務需要對一張大表的乙個列值進行update更新,表中有資料一億多條,為了更新這一億多條資料,我做了一下嘗試,給各位同學留個前車之鑑。表名 test 列名 name varchar2 50 方法一 直接對大表update,語句 update test set name replace name,...