常用mysql笔记
1、insert into ... values
insert into tables (col1,col2) values (1,2),(2,3);
2、insert into ... select
insert into tables (col1,col2) select col3,col4 from table2;
3.insert into ... set
insert into tables set col1=xx,col2=xx;
4.replace into ...
replace into tables set col1=xx,col2=xx; //先删除后插入,如果有自增id,慎用!(唯一索引下才可以用)
5. insert into ... on duplicate key
insert into tables set col1=xx,col2=xx on duplicate key update col1=xxx,col2=xxx; //如果存在则更新,否则就是插入 (唯一索引下才可以用)
6.find_in_set(以逗号隔开,适用与in)
select col1,col2 from tables where FIND_IN_SET(col1,'2,3,4')<1; //col1的值在'2、3、4'里面则返回所在索引(从1开始)
7. group_concat
select group_concat(col1,',',col2) as colx from tables where id={$id} group by id; //将col1,col2的值作为一个字段返回,按逗号分隔。
8.if、ifnull
update tables set status=if(status='release','modifie',status) where id={$id};
9.create database if not exists database1;
10.create table if not exists table1 like table2;
最新文章
- 《连载 | 物联网框架ServerSuperIO教程》- 7.自控通讯模式开发及注意事项
- 【BZOJ 3445】【Usaco2014 Feb】Roadblock
- Python获取中国证券报最新资讯
- ajax传递数组到后台
- javascript高级程序设计---Element对象
- 控制网页的Panel是否显示
- 微博一键分享主要通过对指定 URL 添加各种参数来实现;
- .java 文件中只能定义一个public class 且与文件名相同
- 图形用户界面(graphical user interface)
- 在js中window.open通过“post”传递参数
- 安装centos mini版,无法联网,用yum安装软件提示 cannot find a valid baseurl for repo:base/7/x86_64 的解决方法
- [Linux命令]tar命令
- About Adultism and why things ar the way they are
- c# 快速验证代理IP是否有用
- 关于多字节字符入库失败处理(所谓的Emji),该处理是舍弃特殊字符
- 启动genymotion后eclipse不能正常启动adb的处理办法
- Tasklist使用详解
- 解决在静态页面上使用动态参数,造成spider多次和重复抓取的问题
- Django之路由配置系统(urlConfig)
- 网络编程socket、udp
热门文章
- java学习笔记(13) —— google GSON 实现json转化方法
- centOS上安装redis
- 1106关于解决erp单个商品同步的问题
- Express 学习记录
- 浅谈 “空指针、野指针、void*”
- node.js相关
- 迅雷程浩:企业外包服务,下一个大的风口?(2B业务一定要懂销售和营销的人,这点和2C 不一样)
- 【转】VS2013中如何解决error C4996: &#39;fopen&#39;问题
- 5s
- LINQ 内链接 左链接 右链接