一、登录数据库服务器
二、操作数据库
三、操作表
insert into user values(3,‘ying3’,‘456’,0);
delete from user where id=2;
update user set online=1 where id=3;
- (增)插入表值()
- 从表中删除哪一条
- (改)更新表设置字段哪一条
- 从表中查找字段
- 指定列
- 全部列
- 去重
- 起别名
- 条件查询
- 模糊查询
- in、null、not null、排序、聚合函数(max、min、avg、sum、count人数)
- 分组(分组前的筛选条件用where;分组后的筛选条件用having)
SELECT sex,avg(math) FROM stu GROUP BY sex;
SELECT sex,avg(math),COUNT(*) FROM stu WHERE math>70 GROUP BY sex;
SELECT sex,avg(math),COUNT(*) FROM stu WHERE math>70 GROUP BY sex HAVING sex='男';
- 分页
SELECT * FROM stu LIMIT 3,3;
- 多表查询
select * from emp , dept;
select * from emp , dept where emp.dep_id = dept.did;
select * from emp LEFT JOIN dept ON emp.dep_id = dept.did;
select * from emp RIGHT JOIN dept ON emp.dep_id = dept.did;
- 子查询
select * from emp where salary > (select salary from emp where name = '猪八戒');
select * from emp where dep_id in (select did from dept where dname = '财务部' or dname = '市场部');