mysql insert statement conditionally

Today entrant in the process of seeing a question, probably meant to say, when you meet the conditions for executing the insert statement when they covered, until the situation had never satisfy the conditions did not consider inserted, it has been like this written by
insert into table_name(column...)values(value...)
such statements. So that question does not make it.
Insert statement today put a good refresher.

第一种情况插入指定字段
insert into table_name(column1,column2)values(value1,value2);
第二种情况插入所有字段:前提条件是字段顺序必须与表中字段顺序一致
insert into table_name values(value1,value2);
第三种情况批量插入数据
insert into table_name values (value1,value2),(value1,value2);
也可以指定插入批量数据
insert into table_name(column1,column2) values(value1,value2),(value1,value2);
第四种情况就是当满足了指定条件时才插入数据
insert into (column1,column2) select value1,value2 from table_name where ...
也就是后面select子句中查询出来的列作为前面的值插入到表中,但是这个列的个数要和前面的字段个数一致。select子句就可以随便写了。
例如
insert into dept(deptno,dname,loc) select 11,dept.dname,dept.loc from dept where deptno=22;

Incidentally, review the select, update, delete basic grammar
select sub-query used to select the records meet the conditions, but also frequently used query
select fields from table_name where condition group by group field having the grouping condition order by ordering page offset field limit 0 amount;
on aggregation function sum (), avg (), max (), min () and the like can not be placed back where the conditions such as the need to query information students average more than 80 minutes, should be written sql statement
select * from student group by score having avg(score)>80;
general group and it should be used in conjunction by aggregation function.

update for updating the record
update table_name set column = value where conditions;

delete to delete a record
delete from table_name where condition;

Guess you like

Origin www.cnblogs.com/jasonboren/p/11575077.html