The initialization data update operation mysql

1.单表的:update user set name = (select name from user where id in (select id from user where name='小苏'));

                 update goods set name = REPLACE(name ,' ','') ; //去空格

                 update goods set name = replace (name , ' banana', 'apple'); // change apples bananas
                 update goods set name = price; // assign their data tables to another property

2..update sr_main_ww a set sys_tjzt = 4 where exists (select 1 from sr_main b where a.fk_pk_sr_main = b.pk_sr_main and b.sys_spzt = 1);
exists 用法
3..新建表需要原表的数据(sr_main ,sr_detail ,护理人数计算)
update sr_main a set a.main_xm_nam05 =
(
select count(1)
from sr_detail b
where a.pk_sr_main = b.fk_sr_main
and b.detail_bz_sad06 in ('1','2','3')

)
where a.mdjlx = 'wb_jz';
4..新建表需要原表的数据(sr_main_da ,sr_detail_da ,护理人数计算)
UPDATE sr_main_da a
SET a.main_xm_nam05 = (
SELECT
count(1)
FROM
sr_detail_da b
WHERE
a.sjbfyzj = b.fk_sr_main
AND a.sjbfnf = b.sjbfnf
AND a.sjbfyf = b.sjbfyf
AND a.sjbfnf = '2019'
AND a.sjbfyf = '11'
AND a.mdjlx = 'wb_jz'
AND detail_bz_sad06 IN ('1', '2', '3')
)
WHERE
a.mdjlx = 'wb_jz'
AND a.sjbfnf = '2019'
AND a.sjbfyf = '11'

 5.right, using the left function

Update qlsx_bgqx, permanent
----- update ycs_qlsx set qlsx_bgqx = 'permanent';
update qlsx_bm, need -
----- Update ycs_qlsx qlsx_bm = SET (right (QLSXJBM,. 9));
update qlsx_lx
----- Update SET = qlsx_lx ycs_qlsx (left (QLSXJBM, 2));
----- Update ycs_qlsx the WHEN SET qlsx_lx qlsx_lx the CASE = = 'license' THEN '01' WHEN qlsx_lx = ' punishment' THEN '03' WHEN qlsx_lx = ' forced' THEN '04'
the WHEN qlsx_lx = 'levy' THEN '05' WHEN qlsx_lx = ' pay' THEN '06' WHEN qlsx_lx = ' ruling' THEN '07' WHEN qlsx_lx = ' confirm' THEN '08'
the WHEN qlsx_lx = 'reward' THEN '09' WHEN qlsx_lx = 'power' THEN '10' WHEN qlsx_lx = ' service' THEN '14'
the END;

Guess you like

Origin www.cnblogs.com/tongcc/p/12232665.html