一,查询
- 内链接
select * from a inner join b on a.id = b.id
2.外连接
select * from a ,b where a.id = b.id
3.左连接
select * from a ,b left join b on a.id = b.id
4.右链接
select * from a ,b rigth join b on a.id = b.id
5.子查询
例:查询学生表中大于平局分学生的姓名和成绩
select a.name , a.score from student a where a.score > (select avg(score) from student )
二,删除
delete from student where id=1
三,修改
update student set name = “张三” where id= 1
四,添加
insert into student values (id=“1”,name=“张三”,sex=“男”), (id=“2”,name=“李四”,sex=“女”)
五,常用关键字
排序 order by asc 降序 desc升序
分组 group by
聚合函数:最大值 max,最小值 min,平均数 avg,求和 count
分页 limit 0,2 第0页 第二条数据
合成一个表 union 将两个表中不重复的数据显示出来,not in 将两个表中不同的数据显示出来
和 and 或者 or 加条件 where