因為with必須緊跟引用的select語句,而不是delete,update,merge等。
所以有2種方式:
方式1.
update table1 b set b.NAME=( with t as ( select * from temp ) select a.NAME from table2 a where a.ID=b.ID ) where exists(select 1....)
方式2.
和merge into 一起使用
merge into table1 a using( with t as ( select * from ...... ) select a.NAME from table2 inner join t a on ...... ) b on (a.id = b.id and ......) when matched then update set a.NAME=b.NAME
--delete where a.nums=0
特別說明:
DELETE字句只能寫在MATCHED情況中,不匹配時無法刪除會報錯。
當DELETE跟在UPDATE子句之后時,DELETE字句是針對UPDATE字句修改后的數據進行過濾的。
比如需要刪除所有C字段="0"的數據,UPDATE字句將所有數據的C字段都更新為0,
那么會刪除所有數據,而不是原本為0的數據。