Chinaunix首页 | 论坛 | 博客
  • 博客访问: 87821
  • 博文数量: 5
  • 博客积分: 85
  • 博客等级: 民兵
  • 技术积分: 149
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-09 10:35
文章分类

全部博文(5)

文章存档

2014年(1)

2013年(2)

2012年(2)

我的朋友

分类: Mysql/postgreSQL

2014-05-13 14:34:24

一、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);

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


阅读(5997) | 评论(1) | 转发(3) |
0

上一篇:JQuery元素控制

下一篇:没有了

给主人留下些什么吧!~~

Madon_he2014-05-14 21:55:49

要增加的还挺多,而且你说的太不具体了。只是一个大概。我来补刀
添加备注
update student set 成绩=‘95’,备注=‘勤奋好学’ where 姓名=‘王兰’
成绩90-100的学生
select * from student where 成绩 between 90 and 100
姓刘的信息
select * from student where 姓名 like ‘刘%’
查备注不为空的学生
select * from student where 备注 is not null
看前5行的内容
select top 5 * from student
名字该name   身份证显示idcard