mysql之資料初始化update操作

2022-06-27 12:24:08 字數 2459 閱讀 1991

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,'香蕉','蘋果') ; //香蕉換蘋果

update goods set name = price ; //將自己表中的資料賦值給另外乙個屬性

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,left函式的運用

更新qlsx_bgqx,永久

-----update ycs_qlsx set qlsx_bgqx='永久';

更新qlsx_bm,需要-

-----update ycs_qlsx set qlsx_bm=(right(qlsxjbm, 9));

更新qlsx_lx

-----update ycs_qlsx set qlsx_lx=(left(qlsxjbm, 2));

-----update ycs_qlsx set qlsx_lx = case when qlsx_lx='許可' then '01' when qlsx_lx='處罰' then '03' when qlsx_lx='強制' then '04'

when qlsx_lx='徵收' then '05' when qlsx_lx='給付' then '06' when qlsx_lx='裁決' then '07' when qlsx_lx='確認' then '08'

when qlsx_lx='獎勵' then '09' when qlsx_lx='權力' then '10' when qlsx_lx='服務' then '14'

end ;

6.多個欄位的更新

update sr_zjff_main_btff

set zzhs = (

select

count(1)

from

sr_main_da_btff

where

fk_sr_zjff_main = ?

and sys_spzt = 1

and sys_scbj = 0

),zzrs = (

select

sum(mxsrs)

from

sr_main_da_btff

where

fk_sr_zjff_main = ?

and sys_spzt = 1

and sys_scbj = 0

),zzje = (

select

sum(btffje)

from

sr_main_da_btff

where

fk_sr_zjff_main = ?

and sys_spzt = 1

and sys_scbj = 0

)where

pk_sr_zjff_main_btff = ?

mysql 初始化 MySQL初始化

port 3306 設定mysql的安裝目錄 basedir d php apmw mysql 8.0.17 設定mysql資料庫的資料的存放目錄 datadir d php apmw mysql 8.0.17 data 允許最大連線數 max connections 200 允許連線失敗的次數。m...

mysql 初始化序列 mysql初始化

mysqld nt remove mysql mysqld nt install mysqld initialize insecure user mysql mysqld install mysql root使用者拒絕連線 建立my.ini放在bin下 mysqld 設定3306埠 port 330...

mysql 初始化 mysql時間初始化

date forma t date,format 根據格式串format 格式化日期或日期和時間值date,返回結果串。可用date format 來格式化date 或datetime 值,以便得到所希望的格式。根據format字串格式化date值 s,s 兩位數字形式的秒 00,01,59 i 兩...