INSERT and UPDATE SQL statements of

. 1  # the INSERT statement to write one or more records Syntax
 2  the INSERT  the INTO t_dept is (DEPTNO, DNAME, LOC) the VALUES ( 50 , "Technology", "Beijing");
 . 3  the INSERT  the INTO t_dept is (DEPTNO, DNAME, LOC) the VALUES ( 60 "logistics", "Beijing"), ( 70 "security department", "Beijing");
 4  # to add a technical department employee records
 5  INSERT  iNTO t_emp (empno, ename, the Job, MGR, the HireDate, SAL, COMM, DEPTNO) 
  the VALUES ( 8001 , "Liu Na", "SALESMAN", 8000 , " 1988 - 12 is - 20 is ", 2000 ,NULL,(SELECT deptno FROM t_dept WHERE dname="技术部")); 6 # INSERT方言 7 INSERT INTO t_emp SET empno=8002,ename="JACK",job="SALESMAN",mgr=8000,hiredate="1985-3-14",sal=2500,comm=NULL,deptno=50; 8 # IGNORE关键字 9 INSERT IGNORE INTOt_dept (deptno, DNAME, LOC) VALUES ( 40 , "Technology", "Beijing"), ( 80 "personnel department", "Beijing"); 10 # UPDATE each employee's number and the number will increase by one boss , complete with the ORDER bY clause. 11 UPDATE t_emp the SET empno = empno + 1 , MGR = MGR + 1 the ORDER BY empno DESC ; 12 # UPDATE monthly income of three employees basic salary minus $ 100, complete with a LIMIT clause. 13 is the UPDATE t_emp the SET SAL = SAL - 100 the ORDER BY (SAL + the IFNULL (COMM, 0)) DESC the LIMIT . 3 ; 14 # 10 sectors which seniority over 20 years employees salary increase 200 yuan 15 the UPDATE t_emp the SET SAL = SAL + 200 is the WHERE DEPTNO = 10 the AND the DATEDIFF (the NOW (), HireDate) / 365 > = 20 is ; 16 # ALLEN transferred to the RESEARCH department, position change ANYLYST 17 UPDATE t_emp E JOIN t_dept d the SET e.deptno = d.deptno, e.job = "ANALYST" the WHERE e.ename = "ALLEN" the ANDd.dname = "s"; 18 is # below the company salary average salary of employees salary increase 150 . 19 the UPDATE t_emp E the JOIN ( the SELECT the AVG (SAL) AVG the FROM t_emp) T the ON e.sal < T. AVG the SET e.sal = e.sal + 150 20 # or the staff department not less than 2000 SALES salary employees are transferred to 20 sector 21 is the UPDATE t_emp E the LEFT the JOIN t_dept is D the ON e.deptno = d.deptno the SET e.deptno = 20 the WHERE E .deptno IS NULL OR(d.dname="SALES" AND e.sal<2000);

Table connection, the connection table or table join, the important thing to say three times

Guess you like

Origin www.cnblogs.com/fly10086/p/12514636.html