一、insert(增)
1、将一个表的某些字段重新建为一个表
insert into `tbnameA`(a,b,c) select a,b,c from `tbnameB`

二、delete(删)
1、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录
delete from tbname
where peopleId in (select peopleId from tbname group by peopleId having count(peopleId) > 1)
and rowid not in (select min(rowid) from tbname group by peopleId having count(peopleId )>1)
注:会报1093错误,请把子查询中的tbname改成临时表


三、update(改)
1、同张表把A字段的内容复制到B字段
update tbname set B=A

2、同库不同表,根据两表id值一致,把A表Name字段复制到B表的Name字段
Update A,B Set B.b=A.a Where A.Id=B.Id;
Update A Inner Join B On A.Id=B.Id Set B.Name=A.Name;


四、select(查)
1、查询表中某字段中有中文的数据
SELECT * FROM `tbname` where Name REGEXP concat('[',char(0xE0),'-',char(0xEF),'][',char(0x80),'-',char(0xBF),'][',char(0x80),'-',char(0xBF),']');

2、获得指定表字段
use information_schema;
select column_name from columns where table_name='tabllename';

3、获取表中某字段符合包含某字符串的数据
SELECT * FROM `pre_forum_post_copy` WHERE LOCATE(2143842,pid);

后续会不断补充增加!欢迎大家补充


01-19 01:22