原因:需要批量更新 把A表的某个字段值 替换到B表的某个字段值
我得具体例子:
with 是临时表 , update 关键点在于 from !!!!!! 还能这么写!!!!
update t_temp_kind_field_20211029 set c_relation_id = tt.c_task_id from temp_1029 tt where tt.c_id = c_relation_id;
----更新t_temp_kind_field_20211029
with temp_1029 as (
select c_id,c_task_id from t_temp_module_20211029 where c_task_id in (SELECT
c_id
FROM
t_temp_stage_task
WHERE
c_id IN (
SELECT
c_task_id
FROM
t_temp_module
WHERE
c_id IN (
SELECT
c_relation_id
FROM
t_temp_kind_field
WHERE
c_name LIKE '%诉讼/仲裁请求%'
AND to_number(c_relation_id, '999999999') < 2000
)
AND c_name LIKE '%请求%'
)
AND to_number(c_task_type, '9999999999') < 50
AND c_name LIKE '%申请和解、调解%')
)
--select tt.* from t_temp_kind_field kk,temp_1029 tt where kk.c_relation_id = tt.c_id
update t_temp_kind_field_20211029 set c_relation_id = tt.c_task_id from temp_1029 tt where tt.c_id = c_relation_id;
---更新t_temp_module_20211029
with temp_1029 as (
select c_id,c_task_id from t_temp_module_20211029 where c_task_id in (SELECT
c_id
FROM
t_temp_stage_task
WHERE
c_id IN (
SELECT
c_task_id
FROM
t_temp_module
WHERE
c_id IN (
SELECT
c_relation_id
FROM
t_temp_kind_field
WHERE
c_name LIKE '%诉讼/仲裁请求%'
AND to_number(c_relation_id, '999999999') < 2000
)
AND c_name LIKE '%请求%'
)
AND to_number(c_task_type, '9999999999') < 50
AND c_name LIKE '%申请和解、调解%')
)
update t_temp_module_20211029 set c_task_id = null where c_id in (
select c_id from t_temp_module_20211029 where c_task_id in (SELECT
c_id
FROM
t_temp_stage_task
WHERE
c_id IN (
SELECT
c_task_id
FROM
t_temp_module
WHERE
c_id IN (
SELECT
c_relation_id
FROM
t_temp_kind_field
WHERE
c_name LIKE '%诉讼/仲裁请求%'
AND to_number(c_relation_id, '999999999') < 2000
)
AND c_name LIKE '%请求%'
)
AND to_number(c_task_type, '9999999999') < 50
AND c_name LIKE '%申请和解、调解%'))