一、
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);
后续会不断补充增加!欢迎大家补充
阅读(2975) | 评论(0) | 转发(0) |