插入如下的表格
/*插入表格*/ CREATE TABLE sanguo( empno INT, ename VARCHAR(20), job VARCHAR(20), mgr INT, hiredte DATE, sal DOUBLE, comm DOUBLE, deptno INT ); SELECT * FROM sanguo; ALTER TABLE sanguo CHANGE COLUMN hiredte hiredate DATE; /*填入数据*/ INSERT INTO sanguo VALUES(1001,‘甘宁‘,‘文员‘,1013,‘20001217‘,8000.00,NULL,20); INSERT INTO sanguo VALUES(1002,‘戴绮斯‘,‘销售员‘,1006,‘2001-02-20‘,16000.00,3000.00,30); INSERT INTO sanguo VALUES(1003,‘殷天正‘,‘销售员‘,1006,‘2001-02-22‘,12500.00,5000.00,30); INSERT INTO sanguo VALUES(1004,‘刘备‘,‘经理‘,1009,‘2001-04-02‘,29750.00,NULL,20); INSERT INTO sanguo VALUES(1005,‘谢逊‘,‘销售员‘,1006,‘2001-09-28‘,12500.00,14000.00,30); INSERT INTO sanguo VALUES(1006,‘关羽‘,‘经理‘,1009,‘2001-05-01‘,28500.00,NULL,30); INSERT INTO sanguo VALUES(1007,‘张飞‘,‘经理‘,1009,‘2001-09-01‘,24500.00,NULL,10); INSERT INTO sanguo VALUES(1008,‘诸葛亮‘,‘分析师‘,1004,‘2007-04-19‘,30000.00,NULL,20); INSERT INTO sanguo VALUES(1009,‘曾阿牛‘,‘董事长‘,NULL,‘2001-11-17‘,50000.00,NULL,10); INSERT INTO sanguo VALUES(1010,‘韦一笑‘,‘销售员‘,1006,‘2001-09-08‘,15000.00,0.00,30); INSERT INTO sanguo VALUES(1011,‘周泰‘,‘文员‘,1008,‘2007-05-23‘,11000.00,NULL,20); INSERT INTO sanguo VALUES(1012,‘程普‘,‘文员‘,1006,‘2001-12-03‘,9500.00,NULL,30); INSERT INTO sanguo VALUES(1013,‘庞统‘,‘分析师‘,1004,‘2001-12-03‘,30000.00,NULL,20); INSERT INTO sanguo VALUES(1014,‘黄盖‘,‘文员‘,1007,‘2002-01-23‘,13000.00,NULL,10); INSERT INTO sanguo VALUES(1015,‘张三‘,‘保洁员‘,1001,‘2013-05-01‘,80000.00,50000.00,50); /*查询所有部门编号为30的员工*/ SELECT * FROM sanguo WHERE deptno = 30; /*查询所有职位为销售员的员工的编号,姓名,部门编号*/ SELECT empno,ename,deptno FROM sanguo WHERE job = ‘销售员‘; /*查询所有奖金大于工资的员工*/ SELECT * FROM sanguo WHERE comm > sal ; /*查询所有奖金大于工资60%的员工*/ SELECT * FROM sanguo WHERE comm > (0.6*sal); /*查询所有部门编号为10同时是经理或者部门编号为20同时是销售员的员工*/ SELECT * FROM sanguo WHERE ( deptno = 10 AND job = ‘经理‘) OR (deptno = 20 AND job = ‘销售员‘ ); /*查询所有部门编号为10同时是经理或者部门编号为20同时是销售员或奖金大于20000的员工*/ SELECT * FROM sanguo WHERE ( deptno = 10 AND job = ‘经理‘) OR (deptno = 20 AND job = ‘销售员‘ )OR(comm >= 20000); /*查询所有没有奖金或奖金小于1000的员工*/ SELECT ename FROM sanguo WHERE comm IS NULL OR comm < 1000; /*查询所有名字是三个字的员工*/ SELECT ename FROM sanguo WHERE ename LIKE ‘___‘; /*查询所有2000年加入公司的员工*/ SELECT * FROM sanguo WHERE hiredate LIKE ‘2000%‘; /*查询所有员工详细信息,用编号升序排序*/ SELECT * FROM sanguo ORDER BY empno ASC; /*查询所有员工详细信息,用工资降序排序,如果工资相同使用入职日期升序排序*/ SELECT * FROM sanguo ORDER BY sal DESC,hiredate ASC; /*查询姓周的两个名字的员工。*/ SELECT * FROM sanguo WHERE ename LIKE ‘周_‘; /*查询所有姓张的员工。*/ SELECT * FROM sanguo WHERE ename LIKE ‘张%‘; /*查询该部门有多少个岗位,每个岗位有多少人。*/ SELECT job,COUNT(*) FROM sanguo GROUP BY job; /*查询哪个岗位中人数大于3。*/ SELECT job FROM sanguo GROUP BY job HAVING COUNT(*)>3;
原文地址:https://www.cnblogs.com/zhangrui0328/p/8990894.html
时间: 2024-11-09 03:54:24