1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| drop table `dept`; drop table `emp`;
show create table dept;
create table dept( deptno int(11) not null primary key COMMENT'部门编号(主键)', dname varchar(14) COMMENT'部门名字', loc varchar(13) COMMENT'地址' ) character set utf8;
create table emp( empno int(11) not null primary key COMMENT'员工编号', ename varchar(10) COMMENT'员工姓名', job varchar(9) COMMENT'岗位', mgr int COMMENT'直接领导编号', hiredate date COMMENT'雇佣日期,入职日期', sal int COMMENT'薪水', comm int COMMENT'提成', deptno int not null COMMENT'部门编号'
) character set utf8;
insert into dept values(10,'财务部','北京'); insert into dept values(20,'研发部','上海'); insert into dept values(30,'销售部','广州'); insert into dept values(40,'行政部','深圳'); insert into emp values(7369,'刘一','职员',7902,'1980-12-17',800,null,20); insert into emp values(7499,'陈二','推销员',7698,'1981-02-20',1600,300,30); insert into emp values(7521,'张三','推销员',7698,'1981-02-22',1250,500,30); insert into emp values(7566,'李四','经理',7839,'1981-04-02',2975,null,20); insert into emp values(7654,'王五','推销员',7698,'1981-09-28',1250,1400,30); insert into emp values(7698,'赵六','经理',7839,'1981-05-01',2850,null,30); insert into emp values(7782,'孙七','经理',7839,'1981-06-09',2450,null,10); insert into emp values(7788,'周八','分析师',7566,'1987-06-13',3000,null,20); insert into emp values(7839,'吴九','总裁',null,'1981-11-17',5000,null,10); insert into emp values(7844,'郑十','推销员',7698,'1981-09-08',1500,0,30); insert into emp values(7876,'郭十一','职员',7788,'1987-06-13',1100,null,20); insert into emp values(7900,'钱多多','职员',7698,'1981-12-03',950,null,30); insert into emp values(7902,'大锦鲤','分析师',7566,'1981-12-03',3000,null,20); insert into emp values(7934,'木有钱','职员',7782,'1983-01-23',1300,null,10);
insert into emp(empno, ename, job, hiredate, sal, deptno) values (78933, 'FFOOW', '清洁工', '1981-06-01', 1000, 10), (7937, 'SAMA', '清洁工', '1981-06-01', 1000, 10), (7979, 'MAKE', '清洁工', '1981-06-01', 1000, 10), (7833, 'CARI', '清洁工', '1981-06-01', 1000, 10) ;
select deptno, avg(sal) from emp group by deptno;
SELECT emp.deptno, emp.`ename`,sal, temp.avg_sal FROM emp, (select deptno, avg(sal) avg_sal from emp group by deptno ) temp where temp.deptno = emp.deptno and temp.avg_sal < emp.sal;
desc dept;
show index from emp; show indexes from emp; show keys from emp;
select @@tx_isolation;
desc dept; desc emp;
|