1.检索数据
检索不同的行
select distinct 行 from 表;
限制结果
select 行 from 表 limit 3 ; ( 3 表示,限制行数)
select 行 from 表 limit 3 , 3 ; ( 从行3 开始的3 行)
使用完全限制的表名
select 表. 行 from 表;
2.排序检索数据
排序数据
select 行 from 表 order by 行; (以字母顺序排列行)
降序排序数据
select 行 from 表 order by 行 desc ; (以字母顺序排列行)
3.过滤数据
select 行 from 表 where = 值;
select 行 from 表 where 行 is null ; ( 空值检查)
select 行 from 表 where 行 between 5 and 10 ; ( 范围值检查)
4.数据过滤
AND操作符
select 行, 行, 行 from 表 where 行 = 值 and where 行 = 值;
OR操作符
select 行, 行, 行 from 表 where 行 = 值 or where 行 = 值;
计算次序
select 行, 行, 行 from 表 ( where 行 = 值 or where 行 = 值) and 行 > 10 ;
IN操作符
select 行, 行 from 表 where 行 in ( 1002 , 1003 ) ; ( 表示指定条件范围之内)
NOT操作符
select 行, 行 from 表 where 行 NOT in ( 1002 , 1003 ) ; ( 表示否定指定条件范围之内)
4.通配符过滤
百分号%通配符
select 行 from 表 where 行 like '%anvijj' ; ( 以anvijj结尾的字符,可放结尾,中间,任何地方)
下划线‘_’通配符
select 行 from 表 where 行 like '_anvijj' ; ( 下划线表示单个字符)
5.正则表达式过滤
基本字符匹配
select 行from user where 行 regexp 'rr' ; (包含'rr' 字符)
进行OR匹配
select 行 from user where 行 regexp 'rr||bb' ; (包含'rr' 字符或者'bb' )
匹配范围
select 行 from user where 行 regexp '[123]ii' ; (匹配1 或2 或3 )
匹配特殊字符
select 行 from user where 行 regexp '\\.' ; (在\\后加特殊字符)
6.计算字段
使用别名拼接字段
select Concat( RTrim( name) , '(' , RTrim( extra) , ')' ) AS title from user ;
7.汇总数据
AVG函数
select avg ( 行) from 表; ( 返回行数值的平均数)
COUNT函数
select COUNT ( 行) / min ( ) / max ( ) / sum ( ) / from 表; ( 返回行的总数, 最小值,最大值,总和)
7.插入数据
数据插入
insert into user ( id, name, sex, home, password, extra)
values ( null , '刘山' , '女' , '甘肃' , '777' , 'jeceed' ) ; (多行重复写)
插入检索出来的数据
insert into user ( id, name, sex, home, password, extra)
select id, name, sex, home, password, extra;
更新数据和删除数据
更新数据
update user set name = '历虹' where id = 3 ;
删除数据
delete from user where id = 3 ;
创建联结
select