#查询数据 SELECT
select 字段或表达式 from 表名,视图,结果集
where 条件 (单一条件或组合条件)
GROUP BY 分组
having 分组之后进行检索
order by 排序
limit 限制结果
select * from classroom;
#查询所有员工姓名和工资
select ename, sal from emp;
#查询工资> 2000的所有员工信息
select * from emp where sal > 2000;
#查询工资在1000到2000之间的员工信息(范围查询)
select * from emp where sal =< 2000 and sal >= 2000;
select * from emp where sal between 1000 and 2000;
#查询员工编号为111,222,333的员工信息
select * from emp where empno in (111,222,333);
select * fromo emp where empno = 111 or empno = 222 or empno = 333;
#别名(简化 做解释说明)[as] 别名
#字段,表达式,结果集 都可以起别名
计算员工工资增长5%薪资查询出来sal*1.05给个别名nsal
select ename ,sal *1.05 nsal from emp;
#给表起别名
select e.ename from emp e;
select c.cname from classroom c;
#查询所有职位信息 去重给字段前加distinct
select distinct job from emp;
select distinct cname from classroom1;
#查询再10号部门工资最高的员工信息
#1。10号部门所有员工
#2. 排序,取第一个
#3。函数取最大值
#1
select *from emp where deptno =10;
#2,排序 order by 排序字段 asc升序,desc降序
#根据员工工资降序排序,工资一致按照员工编号降序排序
select * from emp order by sal,empno desc;
#其他表自测
select * from classroom1 order by `desc`desc,cid desc
select * from classroom1 order by `desc` desc
#限制结果查询 limit 下标,长度 (仅适用于MySQL)取前5条数据
select * from emp limit 0,5;
#查询所有有奖金的员工信息
select *from emp where comm is not null;
#模糊查询 like %:0到多个任意字符 _代表1个字符
#查询名字以s大头的员工信息
select *from emp where ename like '%s';
select *from classroom1 where cname like 'bd%';
#查询名字以s结尾的员工信息
#查询名字中包含s的员工信息
select *from emp where ename like '%s%';
select *from classroom1 where cname like '%d%';
#查询第二个字符为L的所有员工信息
select *from emp where ename like '_l%';
select *from classroom1 where `desc` like '_描述%';
#将奖金<500的员工奖金提升100,没有奖金的人comm为null
update emp1 set comm = comm +100 where comm <500;
update emp1 set comm = 100 where comm is null;
#使用ifnull函数,将comm 为null 的置为0
update emp1 set comm = ifnull(comm,0) + 100 where comm is null or comm < 500
update classroom set description = ifnull(description,0) +2 where description is null or description < 3;