MySQL之高级增删改查一
一、select all/distinct 字段名/别名 from table where条件+【1】+【2】+【3】;
where条件:>,<,≥,≤,like,between and(闭区间),in ,not in,与&&,或||,非!
all:查询去全部
distinct:去掉重复的结果
【1】:group by 【asc/desc】 asc:升序,desc:降序
【2】:order by
【3】:limit limit 3:取前3条记录;limit 2,3:从第三条记录开始,共取3条记录(从位置2开始,length为3)----可以用来分页
1、举例演示
先建一个表,id为主键(primary key),且自增长(auto_increment)
create table testabc (id int primary key auto_increment,name varchar(4));
添加数据
insert into testabc set name='a';
批量添加
insert into testabc (name) values ('a'),('b'),('c'),('c'),('a'),('a');
select * from testabc where name='a';
select * from testabc group by name;
限制前3个 select * from testabc limit 3;
select * from testabc limit 2,3; 从第三条记录开始,共取3条记录(从位置2开始,length为3)
二、常用函数max(),min(),avg(),count(),count()---记录值为NULL时不统计入数
1、举例演示,表如下
select max(age) from stu;
select sex, count(*) from stu group by sex;
select sex,count(*),max(age),avg(age) from stu group by sex;
最新文章
- Python-Mac 安装 PyQt4
- 高亮 TRichEdit 当前行
- Tomcat 安装--小白教程
- sql: sq_helptext
- asp.net 中json字符串转换
- 人生规划和GTD——“知”、“得”与“合”
- Linux shell入门基础(七)
- [CSS] CSS Transitions: Delays and Multiple Properties
- 手机端 UI一些插件
- JAVA FILE or I/O学习 - File学习
- 彻底卸载 postgreSQL .etc
- Oozie安装时放置Mysql驱动包的总结(网上最全)
- Zernike不变矩
- mysql数据库基本使用(增删改查)
- mongodb 集群分片
- TCP连接建立系列 — 客户端的端口选取和重用
- qt之fiddler抓包
- 使用js获取页面参数
- 单列模式,装饰器、new方法、类/静态方法实现单列模式
- PHUML 生成UML类图操作流程
热门文章
- Linux常用目录及目录作用说明
- Leetcode题目101.对称二叉树(简单)
- yum异常: [Errno 14] PYCURL ERROR 22 - ";The requested URL returned error: 404 Not Found";
- TCP拥塞控制算法
- mac mysql重置root用户密码
- 【Webscraper】不懂编程也能爬虫
- layer.js错误Uncaught TypeError: i is not a function
- 齐普夫-Zipf定律
- C#实现MJPEG服务器
- LC 813. Largest Sum of Averages