Database Section 2 SQL Table Creation and Content Insertion and Query

CREATE TABLE employee(
empno INT,
ename VARCHAR(10),
job VARCHAR(10),
mgr INT,
hiredate DATE,
sai DOUBLE,
commn DOUBLE,
deptno INT
)

1. Create an employee table with the following contents:

                                           1. Employee number empno int (numeric type)

                                           2. Employee name ename varchar (field type)

                                           3. Employee position job varchar (field type)

                                           4. Employee supervisor number mgr varchar (field type)

                                           5. Hire date hiredate date (field type)

                                           6. Employee salary sai DOUBLE (numeric floating point type)

                                           7. Employee bonus commn DOUBLE (numeric floating point type)

                                           8. Employee number deptno INT (numeric type)

2. Insert employee information

insert into (for example: commn items are displayed as null) values ​​are display options: the order is employee number, name, superior number, bonus (some are inserted as null), salary, and project number

insert into employee(empno,ename,job,mgr,hiredate,sai,deptno) VALUES(1001,'Ganning','clerk',1013,'2000-12-17',8000.00,20);
INSERT INTO employee( empno,ename,job,mgr,hiredate,sai,commn,deptno) VALUES(1002,'Daiqisi','Salesman',1006,'2001-02-20',16000.00,3000,30);
INSERT INTO employee(empno,ename,job,mgr,hiredate,sai,commn,deptno) VALUES(1003,'Yin Tianzheng','Salesman',1006,'2001-02-22',12500.00,5000,30);
INSERT INTO employee(empno,ename,job,mgr,hiredate,sai,deptno) VALUES(1004,'Liu Bei','Manager',1009,'2001-04-02',29750.00,30);
INSERT INTO employee(empno, ename,job,mgr,hiredate,sai,commn,deptno) VALUES(1005,'Xie Xun','Salesman',1006,'2001-09-28',12500.00,14000,30);
INSERT INTO employee(empno, ename,job,mgr,hiredate,sai,deptno) VALUES(1006,'Guan Yu','Manager',1009,'2001-05-01',28500.00,30);
INSERT INTO employee(empno,ename,job,mgr,hiredate,sai,deptno) VALUES(1007,'Zhang Fei','Manager',1009,'2001-09-01',24500.00,10);
INSERT INTO employee( empno,ename,job,mgr,hiredate,sai,deptno) VALUES(1008,'Zhuge Liang','Analyst',1009,'2001-05-01',28500.00,20);
INSERT INTO employee(empno,ename, job,hiredate,sai,deptno) VALUES(1009,'Zeng Aniu','Chairman','2001-05-01',28500.00,10);
INSERT INTO employee(empno,ename,job,mgr,hiredate, sai,commn,deptno) VALUES(1010,'Wei Yixiao','Salesman',1006,'2001-09-08',15000.00,0.00,30);
INSERT INTO employee(empno,ename,job,mgr,hiredate ,sai,deptno) VALUES(1011,'Zhou Tai','clerk',1008,'2007-05-23',11000.00,20);
INSERT INTO employee(empno,ename,job,mgr,hiredate,sai,deptno ) VALUES(1012,'Cheng Pu','Clerk',1006,'2001-12-03',9500.00,30);
INSERT INTO employee(empno,ename,job,mgr,hiredate,sai,deptno) VALUES(1013,'Pang Tong','Analyst',1004,'2001-12-03',30000.00,20);
INSERT INTO employee( empno,ename,job,mgr,hiredate,sai,deptno) VALUES(1014,'huanggai','clerk',1007,'2001-01-23',13000.00,10);
INSERT INTO employee(empno,ename, job,mgr,hiredate,sai,commn,deptno) VALUES(1015,'Xie Xun','Salesman',1001,'2013-05-01',80000.00,50000,50);

query content

SELECT * FROM employee WHERE deptno=30;/*Query all numbers 30*/
SELECT ename,empno,deptno FROM employee WHERE job='Salesman';/*Salesman's name and number*/
SELECT *FROM employee WHERE commn> sai;/*bonus is higher than salary*/
SELECT *FROM employee WHERE commn>sai*0.16;/*bonus is higher than salary*/
SELECT* FROM employee WHERE(deptno=10 AND job='manager')OR(deptno=20 AND job='Salesman');/*Manager and Salesman with numbers 10 and 20*/
SELECT * FROM employee WHERE(deptno=10 AND job='Manager')OR(deptno=20 AND job=' Salesperson')OR(job<>'manager' AND job<>'salesperson' AND sai>20000);/*The salary of managers and salespersons numbered 10 and 20 and neither manager nor salesperson is greater than 2000 people */
SELECT * FROM employee WHERE(commn<1000)OR(commn=NULL);/*bonus is less than 1000 or bonus is empty*/
SELECT * FROM employee WHERE ename LIKE '___';/*Query employees composed of three names (temporarily unavailable)*/
SELECT * FROM employee WHERE hiredate LIKE '2000%';/*The table of employees who joined in 2000*/
SELECT * FROM employee ORDER BY empno ASC;/*The employee details are sorted in ascending order*/
SELECT * FROM employee ORDER BY sai DESC,hiredate ASC;/*The salary descending order entry years are the same ascending order*/
SELECT * FROM employee WHERE ename LIKE 'week_ ';/*The name of the two-character employee with the last name Zhou*/
SELECT * FROM employee WHERE ename LIKE 'Zhang%';/*All managers with the last name Zhang*/
SELECT job,COUNT(*) FROM employee GROUP BY job;/ *How many jobs does this department have*/
SELECT job,COUNT(*) FROM employee GROUP BY job HAVING COUNT(*)>3; /*Which department has more than 3 people*/

The above 16 items are the most detailed conditions for the query and the most comprehensive learning content.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325271458&siteId=291194637
Recommended