create database
创建数据库
show database
查看数据库
use
选择数据库
show tables
查看表
drop database
删除数据库
创建表
create table 表名(
字段名1 字段类型,
字段名2 字段类型
)
查看表的定义
desc 表名;
删除表
drop table 表名
插入记录
insert into 表名(字段1,字段2,字段3) values(值1,值2,值3);
一次插入多条记录
insert into 表名(字段1,字段2,字段3)
values
(值1,值2,值3),
(值1,值2,值3),
(值1,值2,值3)
;
修改记录
update 表名 set 字段1=值1,字段2=值2,…字段n=值n where 条件;
修改多个表中数据
updata 表1,表2,…表n set 表1.字段1=表达式1,字段n=表达式n where 条件;
举例
update t1,t2 set t1.age=1000,t2.age=2000 where t1.id=1 and t2.id=1;
删除记录
删除单表中的数据
delete from 表名 where 条件;
删除多个表中的数据
delete 表1,表2,…表n from 表1,表2,…表n where 条件;
查询记录
select 字段名1 from 表名
查询表有多少条记录
select count(*) from table;
聚合
sum求和
select sum(字段名) from 表名
count记录总数
select count(*|字段名) from 表名
max最大值
select max(字段名) from 表名
min最小值
select min(字段名) from 表名
group by 分组
select deparment,sum(salary) from employee group by department;
with rollup
having条件
表连接
内连接
select * from employee,employee_record where employee.id=employee_record.cid;
子查询
select * from employee where id in (select eid from employee_late);