update user_item set addr=REPLACE(addr,'年','-') where time<'2013-11-5';
update phpyun_resume set birthday=REPLACE(birthday,'年','-');
update phpyun_resume set birthday=REPLACE(birthday,'月','-');
update phpyun_resume set birthday=REPLACE(birthday,'日','');
update phpyun_resume set sex=REPLACE(sex,'6','1');
以上是改、更新
DELETE FROM phpyunrc45_company_job WHERE linkman like'%速度%';
以上是删除
MYSQL增删改查
一、数据查询
数据库管理系统的一个最主要的功能就是数据查询,数据查询不应只是简单查询数据库中存储的数据,还应该,根据需要对数据进行筛选,以及确定数据以什么样的格式显示。
下面首先介绍如何使用SELECT语句查询数据表中的一列或多列数据、使用集合函数显示查询结果、连接查询、子查询以及使用正则表达式查询等。
SELECT语句的基本格式是:
SELECT
{ * | <字段列表>}
[
FROM <表1>,<表2>........
[WHERE <表达式>
[GROUP BY <group by definition>]
[HAVING <expression> ]
[ORDER BY <order by definition>]
[LIMIT [<offset>,]<row count>]
]
或者
SELECT [字段1,字段2,......,字段n]
FROM [表或视图]
WHERE [查询条件];
根据开发人员习惯将关键字使用大写,而数据列和表名使用小写,读者应该养成一个良好的习惯,这样更易于阅读和维护;
1、单表查询:指从一张表数据中查询所需的数据。
1.1、查询所有字段: SELECT * FROM 表名 ;
1.2、查询指定字段: SELECT 列名 FROM 表名 ;
1.3、查询指定记录:数据库中包含大量的数据,根据特殊要求,可能只需要查询表中的指定数据,即对数据进行过滤;
SELECT 字段1、字段2、,...字段n
FROM 表名
WHERE 查询条件 ;
1.4、带IN关键字的查询:用来查询满足指定范围内的条件的记录 ;
SELECT s_id, f_name
FROM fruits
WHERE s_id IN (101 , 102)
ORDER BY f_name ;
相反的,可以使用关键字NOT来检索不在条件范围内的记录 ;
1.5、带BETWEEN AND 的范围查询:用来查询某个范围内的值;
例如:查询价格在2.00元到10.20元之间的水果名称和价格 ;
SELECT f_name , f_price FROM fruits WHERE f_price BETWEEN 2.00 AND 10.20 ;
BETWEEN AND操作符前可以加关键字NOT,表示指定范围之外的值,如果字段值不满足指定范围内的值,则这些记录被返回
1.6、带LIKE的字符匹配查询:通配符是一种在SQL的WHERE条件子句中拥有特殊意思的字符 ;
1.6.1:百分号通配符‘%’,匹配任意长度的字符,甚至包括零字符
SELECT f_id, f_name
FROM fruits
WHERE f_name LIKE 'b%'
1.6.2 :下划线通配符 ‘_’,一次只能匹配任意一个字符
1.7、查询空值 :空值不同于0,也不同于空字符串。空值一般表示数据未知 、不适用或将在以后添加数据 ;
SELECT * FROM fruits WHERE f_price IS NULL ;
1.8、带AND的多条件查询 :通过AND增加查询的限制条件,这样可以使查询的结果更加精确 ;
SELECT f_id, f_price FROM fruits WHERE s_id='101' AND f_price >=5 ;
1.9、带 OR 的多条件查询 :使用OR操作符,表示只需要满足其中一个条件的记录即可返回 ;
1.10、查询结果不重复 :有时使用SELECT查询,会出现一些重复的s_id值,有时,出于
对数据分析的要求,需要消除重复的记录值,可以使用 DISTINCT关键字MySQL消除重复的记录值。
SELECT DISTINCT 字段名 FROM 表名 ;
1.11、对查询结果进行排序:ORDER BY 字段名 ; 指定反序方向:ASC (升序排序) DESC(降序排序)
多列排序 : 即首先对第一列字段排序,然后对第一列有相同的字段进行第二次排序 ;
1.12、分组查询 :是对数据 按照某个或多个字段进行分组,MySQL中使用GROUP BY 关键字对数据进行分组。
[GROUP BY 字段] [HAVING <条件表达式>]
GROUP BY 关键字通常和集合函数一起使用,例如:MAX() 、 MIN() 、 COUNT() 、SUM() 、AVG()。
例:SELECT s_id ,COUNT(*) AS Total FROM fruits GROUP BY s_id ;
例:根据s_id 对fruits表中的数据进行分组, 将每个供应商的水果名称显示出来,SQL 语句如下:
SELECT s_id ,GROUP_CONCAT(f_name) AS Names FROM fruits GROUP BY s_id ;
使用HAVING过滤分组:
例:根据s_id对fruits表中的数据进行分组,并显示水果种类大于1的分组信息,SQL语句如下:
SELECT s_id ,GROUP_CONCAT(f_name) AS Names
FROM fruits
GROUP BY s_id HAVING COUNT (f_name) >1 ;
注意: HAVING关键字与WHERE关键字都是用来过滤数据,两者有什么区别呢?其中重要一点是,HAVING在数据分组之后进行过滤来选择分组,而WHERE在分组之前用来选择记录。另外WHERE排除的记录不再包括在分组中。
在GROUOP BY 子句中使用 WITH ROLLUP:使用WITH ROLLUP 关键字之后,在所有查询出的分组记录之后增加一条记录,例:该记录计算查询出的所有记录的总和,即统计记录数量。
SELECT s_id , COUNT(*) AS Total
FROM fruits
GROUP BY s_id WITH ROLLUP ;
2、连接查询:通过连接查询出存放在多个表中的不同实体的信息。当两个或多个表中存在相同意义的字段时,便可以通过这些字段对不同的表进行连接查询 ;
内连接查询:
SELECT suppliers.s_id , s_name , f_name , f_price
FROM fruits , suppliers
WHERE fruits.s_id = suppliers . s_id ;
外连接查询:查询多个表中没有关联的行中数据
3、使用正则表达式查询:通常用来检索或替换那些符合某个模式的文本内容,根据指定的匹配模式匹配文本中符合要求的特殊字符串 ;
1、‘^’匹配文本的开始字符 ‘^b’匹配以字母b开头的客串
2、‘$’匹配文本的结束字符 ‘st$’匹配以st结尾的客串
3、‘.’ 匹配任何单个字符 ‘b.t’匹配任何b和t之间有一个字符的字符串
4、‘*’匹配零个或多个在它前面的字符 ‘f*n’匹配字符n前面有任意个字符f
5、‘+’匹配前面的字符1次或多次 ‘ba+’匹配以b开头后面紧跟至少有一个a
6、‘[^]’匹配不在括号中的任何字符 '[^abc]'匹配任何不包含a、b、或的字符串
7、‘字符串{n}’匹配前面的字符串至少n次 b{2}匹配2个或更多的b
8、 ' 字符串{n,m}' 匹配前面的字符串至少n次,至多m次。
9、 <字符 串> 匹配包含指定的字符串的文本
10、[字符集合] 匹配字符集合中的任何一个字符 '[xz]' 匹配x或者z
二、数据插入 INSERT INTO
1、为表中所有字段插入数据:INSERT INTO table_name (column_list) VALUES (value_list) ;
table_name : 表名 ; column_list :指定要插入数据的哪些列 ; value_list :指定每个列对应插入的数据 ;
2、为表的指定字段插入数据:INSERT INTO person (name , age) VALUES ('xiaoxi',20) ;
3、将查询结果插入到表中:INSERT INTO table_name (column_list1 )
SELECT (column_list2) FROM table_name2
WHERE (condition)
三、更新数据 UPDATA SET
1、基本语法格式如下:
UPDATE table_name
SET column_name1 = value1 , column_name2=value2........column_namen=valuen
WHERE (condition) ;
四、删除数据 DELETE
1、基本语法格式如下:
DELETE FROM table_name [WHERE <condition>] ;
例:删除表中id=11的记录
DELETE FROM person WHERE id=11 ;
首先对MySQL数据库进行了安装与配置,然后又数据库和表的创建,在这里通过功能丰富的数据库管理语句实现了数据的插入,查询,修改,删除等操作。这些基本的操作已经总结完。下面一篇将深入学习索引、存储过程和函数、视图、触发器。
---------------------
作者:Master_ss
来源:CSDN
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%孕%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%手机%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%哪里%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%小孩%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%电话卡%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%体检%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%科目%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%头条%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%驾驶证%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%花呗%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%孩子%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%捐卵%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%高手%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%投注%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%***%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%孩子%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%卵%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%中奖%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%快三%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%代考%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%试管%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%套现%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%招聘高级普工师傅%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%白条%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%发票%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%驾照%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%create%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%车管所%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%驾校%';
DELETE FROM `phpyunrc45_company_job` WHERE `name` LIKE '%驾证%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%孕%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%手机%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%哪里%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%小孩%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%电话卡%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%体检%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%科目%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%头条%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%驾驶证%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%花呗%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%孩子%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%捐卵%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%高手%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%投注%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%***%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%孩子%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%卵%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%中奖%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%快三%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%代考%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%试管%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%套现%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%招聘高级普工师傅%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%白条%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%发票%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%驾照%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%create%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%车管所%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%驾证%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%????????%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%薇亻言%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%484529278%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%爱心%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%ITLEY%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%KGTHT%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%ESMYC%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%WOAPR%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%PFLWR%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%JZDRZ%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%ZXBKX%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%MCRER%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%ENWHI%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%JYKNC%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%专业办理%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%欧博卖分%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%诚信代理%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%波子工作室%';
DELETE FROM `phpyunrc45_company` WHERE `name` LIKE '%广州花花咨询有限公司%';