1.概述
1.1 sql执行顺序
1 执行where子句,从表中选行。
2 执行group by子句,对结果进行分组。
3 执行聚集函数(如count()、max())。
4 执行having子句,过滤分组。
5 排序。
1.2 注释
可以使用/**/,表示块注释。也可以使用"-- a comment",表示行注释。
1.3 引号问题

答:连续两个单引号就表示一个单引号。例:
sql中,insert into yourTable(f1) values(特殊字符串);
字符串内容若为'a"b"c'd'
应写为values('‘'a"bc''d''’)

答:在sql语句中表示字符串类型,单双引号都可以,如'小明'或"小明"都可以。
2.增添
insert into Student values(‘13’,’小明’,’男’,’20’)
按次序将值放在表中。
insert into student (studentName,age) values("小明",10);
将值插入在指定的列中。
3.删除
delete from Student where id=’1’;
删除指定的列。
4.更改
update Student set age=’18’ where name=’小明’;
字符串替换函数:REPLACE(field,targetStr,replacementStr);在field字段副本中,将targerStr替换为replacementStr并返回。例子:
//action字段中,将'blockIp,60'子串替换为'blockIp,2'
UPDATE `cep_rule` set action=REPLACE(action,'blockIp,60','blockIp,2');
5.查询
查询语句中,from后跟表名,可以写from student ,也可以写 from `student`,注意符号不是单引号,而是tab键上面的那个。
select name
as studentName from person;
将原列名换个名字体现在查询结果中。
select * from Student
‘*’为通配符,查询表中所有信息