Mysql一些小技巧

update & select

UPDATE 表a

SET 表a.字段 = 表b.字段

FROM 表a INNER JOIN 表b ON 表b.字段 = 表a.字段

WHERE {CONDITION}

判断null与空

select w.SysNo , w.Name , isnull(w.CellPhone) , w.CellPhone
from worker  w
where 1 = 1
and isnull(w.CellPhone)= 0
and length(trim(w.CellPhone))>0 
;

插入时判重

insert into testmgt.s(name, c) select '一个名字', 123
from dual
WHERE NOT EXISTS (select *
from testmgt.s
where c = 123

posted @ 2022-12-27 19:41  [在河之洲]  阅读(2)  评论(0编辑  收藏  举报