有条件的mysql插⼊语句_mysql中有条件的插⼊语句
今天在参加笔试的过程中,看到⼀道题,⼤概意思就是说,当满⾜了条件就执⾏插⼊语句,当时就蒙了,之前从来都没有考虑过满⾜条件才插⼊的情况,所以⼀直都是这样写的 insert into table_)) 这样的语句。所以那道题没有做出来。 今天就把插⼊语句好好复习⼀下。
第⼀种情况插⼊指定字段minwidth什么时候用
insert into table_name(column1,column2)values(value1,value2);
第⼆种情况插⼊所有字段:前提条件是字段顺序必须与表中字段顺序⼀致
mysql语句分类
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);
switch语句中表达式的类型不能为第四种情况就是当满⾜了指定条件时才插⼊数据
asp命令是什么意思insert into (column1,column2) select value1,value2 from table_name where ...
也就是后⾯select⼦句中查询出来的列作为前⾯的值插⼊到表中,但是这个列的个数要和前⾯的字段个数⼀致。select⼦句就可以随便写了。
例如
ios打开phpinsert into dept(deptno,dname,loc) select 11,dept.dname,dept.loc from dept where deptno=22;
顺便复习⼀下select,update,delete基础语法 select ⼦查询,⽤于选择满⾜条件的记录,也是经常⽤的查询语句 select 字段 from table_name where 条件 group by 分组字段 having分组条件 order by 排序字段 limit 0 分页偏移量; 关于聚合函数
sum(),avg(),max(),min()等是不能放在where条件后⾯的,例如需要查询平均分⼤于80分的同学的信息,应该这样写sql语句 select * from student group by score having avg(score)>80; ⼀般group by 都要和聚合函数⼀起连⽤。
客服在线系统报价update⽤于更新记录 update table_name set column=value where 条件;
delete ⽤于删除⼀条记录 delete from table_name where 条件;