+--------+------------+----------+
| deptno | dname | loc |
+--------+------------+----------+ dept表
| 10 | ACCOUNTING | NEW YORK |
| 20 | RESEARCH | DALLAS |
| 30 | SALES | CHICAGO |
| 40 | OPERATIONS | BOSTON |
+--------+------------+----------+
+-------+--------+-----------+------+------------+------+------+--------+
| empno | ename | job | mgr | hiredate | sal | comm | deptno |
+-------+--------+-----------+------+------------+------+------+--------+
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800 | NULL | 20 |
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600 | 300 | 30 |
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250 | 500 | 30 |
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975 | NULL | 20 |
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250 | 1400 | 30 |
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850 | NULL | 30 |
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450 | NULL | 10 |
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-03 | 3000 | NULL | 20 |
| 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000 | NULL | 10 |
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500 | 0 | 30 |
| 7876 | ADAMS | CLERK | 7788 | 1987-07-13 | 1100 | NULL | 20 |
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950 | NULL | 30 |
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000 | NULL | 20 |
| 7934 | MILLER | CLERK | 7782 | 1981-01-23 | 1300 | NULL | 10 |
+-------+--------+-----------+------+------------+------+------+--------+
--部门表
CREATE TABLE dept(
deptno int PRIMARY KEY,
dname VARCHAR(14) , --部门名称
loc VARCHAR(13) ---部门地址
) ;
--员工表
CREATE TABLE emp(
empno int PRIMARY KEY, --员工编号
ename VARCHAR(10), ---员工姓名
job VARCHAR(9), --员工工作
mgr int, ----员工直属领导编号
hiredate DATE, ----入职时间
sal double, ---工资
comm double, --奖金
deptno int REFERENCES dept); --关联dept表
1、查找部门30中员工的详细信息。
select * from dept d, emp e where d.deptno=e.deptno and d.deptno=30;
答案都没我写的这个难
2、找出从事clerk工作的员工的编号、姓名、部门号。
select deptno,empno,ename from emp where job ='CLERK';
3、检索出奖金多于基本工资的员工信息。
select * from emp where ifnull(comm,0)>sal;
4、检索出奖金多于基本工资60%的员工信息。
select * from emp where ifnull(comm,0)>(sal*0.6);
5、找出10部门的经理、20部门的职员 的员工信息。
select *from emp where deptno=10 and job='MANAGER'or deptno=20 and job='CLERK';
6、找出10部门的经理、20部门的职员 或者既不是经理也不是职员但是工资高于2000元的员工信息。
select * from emp where (deptno=10 and job='MANAGER') or ( deptno=20 and job='CLERK') or ( job not in ('MANAGER','CLERK') and sal>2000);
select * from emp where (deptno = 10 and job='MANAGER') or (deptno=20 and job='CLERK') or (job!='MANAGER' and job!='CLERK' and sal>2000);
select * from emp where job!='MANAGER' and job!='CLERK' and sal>2000;
7、找出获得奖金的员工的工作.
select ename,job from emp where not comm is null && comm >0;
8、找出奖金少于100或者没有获得奖金的员工的信息。
select * from emp where comm is null or comm<100;
9、找出姓名以A、B、S开始的员工信息。
select * from emp where ename like 'A%' or ename like 'B%' or ename like 'S%';
10、找到名字长度为7个字符的员工信息。
select * from emp where ename like '_______';
11、名字中不包含R字符的员工信息。
select * from emp where ename not like '%R%';
12、返回员工的详细信息并按姓名排序。
select * from emp group by ename;
13、返回员工的信息并按工作降序工资升序排列。
select * from emp order by job desc,sal asc;
14、计算员工的日薪(按30天)。
select sal/30 rx from emp;
15、找出姓名中包含A的员工信息。
select * from emp where ename like '%A%';