From
表连接
on连接条件,形成新的虚拟表
where 筛选条件
group by 生成新的结果集合 group by 分组列表
having 分组后筛选
select 选出显示的
order by 排序
limit 分页/个数限制
子查询顺序
除了exists,先执行子查询,再外查询
exists:相关子查询,先执行外查询,再根据子查询字段进行过滤。
分页查询
limit (page-1)*size,size
字符控制函数
substr('helloworld',1,5) hello
instr('helloworld','w') 6
LPAD(salary,10,'*') ****salary
TRIM('H' from 'Helloworld') elloworld
视图应用场景
多个地方用到同样的查询结果
该查询结果会用的SQL语句较复杂
DML 表操作 无table
insert into tableName( column1,column2,...) values(值1,...)
update student
set age=18
where name='hwj'
/* 表数据删除 */delete from student
where age=18/* 多表 */delete from student s1,course c1where s1.class=c1.classand s1.name='mm';# 方式2truncate 语句truncate table student
DDL 管理操作,对表操作要加上字段table
# 创建
create table if not exists student(column1,...)
# 修改 字段名
Alter table student change column 旧 新字段
# 修改表名
Alter table student rename to student1
# 修改字段类型和约束
Alter table tablename modify column column_name 约束
# 添加字段
Alter table 表名 Add column 字段;
# 删除字段
Alter table 表名 drop column 字段
# 删除表
drop table if exists 表名
(责任编辑:范老师)