1、查询表中所有学生的信息
mysql> select * from student;
mysql> select name,english from student;
mysql> select DISTINCT * from student;
mysql> select name,chinese+math+english AS total from student;
mysql> select name,chinese+math+english+10 AS 'total+10' from student;
mysql> select chinese AS 语文 ,math AS 数学,english AS 英语 from student;
mysql> select name from student
-> where english>90;
mysql> select name from student
-> where chinese+math+english > 200;
mysql> select name from student
-> where english BETWEEN 80 AND 90;
mysql> select name from student
-> where not(english>=80 and english<=90);
mysql> select name from student
-> where math in(89,90,90);
mysql> select name from student
-> where math not in(89,90,90);
13、查询所有姓李的学生英语成绩
mysql> select english from student
-> where name like '李%';
mysql> select name from student
-> where math=80 and chinese=80;
mysql> select name from student
-> where english=80 or chinese+math+english=200;
mysql> select math from student
-> order by math DESC;
17、 对总分从高到低的顺序输出
mysql> select chinese+math+english total from student
-> order by chinese+math+english DESC;
mysql> select chinese+math+english total from student
-> where name like '李%'
-> order by chinese+math+english;
19、查询男生和女生分别有多少人,并将人数降序输出
mysql> SELECT gender, COUNT(*) AS count
-> FROM student
-> GROUP BY gender
->ORDER BY count DESC;
20、查询男生和女生分别有多少人,并将人数降序输出,并查询出大于9的性别人数信
mysql> select gender ,count(*) count from student
-> group by gender
-> HAVING count > 9
-> ORDER BY count DESC;
1、按员工编号升序排列不在10号部门工作的员工信息
mysql> select * from emp
-> where deptno != 10;
2、 查询姓名第二个字母不是'A'且薪水大于1000元的员工信息,按薪水降序排列
mysql> select * from emp
-> where ename != '_A%' and sal <= 1000;
mysql> select ename,sal*12+COALESCE(comm,0) '年薪+奖金' from emp
-> order by sal*12+COALESCE(comm,0) DESC;
4、5
mysql> select deptno,avg(sal),max(sal) from emp
-> GROUP BY deptno;
mysql> select deptno,job,max(sal)
-> from emp
-> group by deptno,job
-> order by deptno,max(sal) DESC;
mysql> select deptno,avg(sal) from emp
-> group by deptno
-> having avg(sal) > 2000;
8、将部门平均薪水大于1500的部门编号列出来,按部门平均薪水降序排列
mysql> select deptno,avg(sal) from emp
-> group by deptno
-> having avg(sal) >1500
-> order by avg(sal) desc;
mysql> select ename,sal from emp
-> where comm is not null;
mysql> select max(sal)-min(sal) from emp;
第三张表信息
1. 查询出部门编号为30的所有员工
mysql> select ename,deptno from emp
-> where deptno = 30;
mysql> select ename,empno,deptno from emp
-> where job = '销售员';
3. 找出奖金高于工资的员工。
mysql> select ename from emp
-> where comm > sai;
mysql> select ename from emp
-> where comm > sai*0.6;
5. 找出部门编号为10中所有经理,部门编号为20中所有销售员
mysql> select * from emp
-> where (deptno=10 and job='经理') or (deptno=20 and job='销售员');
6.找出部门编号为10中所有经理,部门编号为20中所有销售员,还有即不是经理又不是销售员但其工资大或等于20000的所有员工详细资料
mysql> select * from emp
-> where (deptno=10 and job='经理')
-> or (deptno=20 and job='销售员')
-> or (job!='经理' and job !='销售员' and sai >=20000);
7.无奖金或奖金低于1000的员工。
mysql> select ename from emp
-> where comm < 1000 OR comm is null;
8.、查询名字由三个字组成的员工。
注意:一个汉字占三个字节
mysql> select ename from emp
-> where ename like '___';
OR
mysql> select ename from emp
-> where LENGTH(ename)=9;
9.查询2000年入职的员工。
mysql> select ename,YEAR(hiredate) from emp
-> where YEAR(hiredate)=2000;
mysql> SELECT * FROM emp
-> order by empno ;
11. 查询所有员工详细信息,用工资降序排序,如果工资相同使用入职日期升序排序
mysql> SELECT * FROM emp
-> order by sai DESC,hiredate;
mysql> select deptno,avg(sai) from emp
-> group by deptno;
13.查询每个部门的雇员数量
mysql> select deptno,count(deptno) from emp
-> group by deptno;
mysql> select job,max(sai),min(sai),count(job) from emp
-> group by job;