mysql单表查询怎么做_mysql单表查询
简单查询:
select * from tb_name
select field1,field2 from tb_name;
select * from tb_name where qualification ;
例子:select name,age from students where age+1>20;
select name from student where age>20 and gender='M';
select name from student where age>20 or gender='M';
select name from student where not age>20 and not gender='M';
select name from student where not (age>20 or gender='M');
select name from student where age>=20 and age<=50;或者select name from student where age between 20 and 25;
select name from student where like name 'Y%';
REGEXP 或者RLIKE 后面可以跟上正则表达式:
select name from student where name relike '^[MNY].*$';匹配以M或者N或者Y开头后面任意字符的。
IN的用法:年龄在18、20、25岁的同学名字
select name from student where age in (18,20,25);
显示student表中cid是null的同学;
select name from student where cid is null;
不是null值的写法:
select name from student where cid is not null;
根据查询到的数据排序:
select name from student where cid is not null order by name;
数据存储的三种格式:堆文件、顺序文件、hash
给字段取别名;
select name as student_name from student where cid is not null order by name;
限制显示的行数(limit);
例子: select name as student_name from student as xiaohai limit 2
限制只显示两行。
略过前两行:
select name as student_name from student as xiaohai limit 2,3
略过前两行显示三行。
聚合计算:
所有同学的平均年龄:
select avg(age) from student;
select max(age) from student;
select min(age) from student;
select sum(age) from student; 求和
select count(age) from student; 求个数
group by :分组
select age,gender from student group by gender;
按照性别把student表分组(即男,女) 显示age gender
select avg(age) from student group by gender;
按照性别把表student分组,分别计算出他们的的平均值。
分组的主要目的是聚合:
注意:对group by 条件进行过滤必须用having 它的作用相当于where
select count(cid1) as persons,cid from student group by cid1 having persons>=2;
having的作用是对group by的结果做再次过滤
mysql单表查询怎么做_mysql单表查询相关推荐
- mysql修改表中学生姓名 专业_MySQL单表练习
1.创建一个名称为mydb1的数据库. Create databasemydb1; 2.创建一个使用utf8字符集的mydb2数据库. createdatabasemydb2charsetutf8; ...
- mysql 多表查询计算平均_MYSQL多表查询
一. 课堂练习以及知识点 表的加法 含义:将两个表按行合并在一起,用union将两个表中的结果合并在一起 案例 select 课程号,课程名称 from course union select 课程号 ...
- mysql多表查询详解_MySQL多表查询详解上
时光在不经意间,总是过得出奇的快.小暑已过,进入中暑,太阳更加热烈的绽放着ta的光芒,...在外面被太阳照顾的人们啊,你们都是勤劳与可爱的人啊.在房子里已各种姿势看我这篇这章的你,既然点了进来,那就由 ...
- mysql多表查询分页面_mysql多表联合查询分点经验给大家
你的位置: 问答吧 -> MySQL -> 问题详情 mysql多表联合查询分点经验给大家 我在工作中天天研究zen cart的程序,那个叫人痛苦,最近比较痛苦的是经常碰见mysql多表联 ...
- mysql 表 视图 索引吗_Mysql多表查询, 视图,事务,索引,函数,go连接数据库
1.1 今日目标 理解多表查询 理解子查询 能够创建视图 能够删除视图 能够查看创建视图的SQL语句 能够理解事务的作用 能够操作事务 理解索引的作用 能够创建索引 能够删除索引 知道常用的函数 了解 ...
- mysql 多表联查的效率_Mysql 多表联合查询效率分析
1 多表连接类型 1. 笛卡尔积(交叉连接) 在MySQL中可以为CROSS JOIN或者省略CROSS即JOIN,或者使用',' 如: SELECT * FROM table1 CROSS JOIN ...
- mysql同步三张表如何用事务_MySQL 多表查询与事务的操作
表连接查询 什么是多表查询 # 数据准备 # 多表查询的作用 * 比如:我们想查询孙悟空的名字和他所在的部门的名字,则需要使用多表查询 # 如果一条 SQL 语句查询多张表,因为查询结果在多张不同的表 ...
- mysql 子查询 博客_mysql——多表——子查询——示例
子查询: 子查询是将一个查询语句嵌套在另外一个查询语句中,内层查询语句的查询结果,可以作为外来层查询语句提供查询条件. 因此在特定条件下,一个查询语句的条件,需要另外一个查询语句来获取. 前期准备表: ...
- asp多表查询并显示_MySQL多表查询与事务
回顾 1. DQL单表高级查询条件 where比较运算逻辑运算符in关键字between关键字if null关键字like关键字% 多个任意字符_ 单个任意字符排序 order byascdesc聚合 ...
- mysql子查询字符串位置_MySql基础-子查询
一.子查询定义 定义: 子查询允许把一个查询嵌套在另一个查询当中. 子查询用()括起来 子查询,又叫内部查询,相对于内部查询,包含内部查询的就称为外部查询. 子查询可以包含普通select可以包括的任 ...
最新文章
- ddr4单颗粒最大_Zynq UltraScale +系列之“DDR4接口设计”
- RocketMQ的Producer详解之分布式事务消息(代码实现以及过程分析)
- Myeclipse 2014配置SVN详细图解
- 中科大 计算机网络2 什么是互联网
- mysql导入sql文件过大或连接超时的解决办法
- Scrapy_CSS选择器
- 无穷大常量0x7fffffff 0x3fffffff 0x3f3f3f3f
- ChIP-seq 数据分析1 ChIP-Seq技术2 ChIP-Seq数据分析
- 安卓加密软件_教你用手机NFC模拟加密门禁卡
- 其实,以前都没发现------网易公开课
- div中img居中显示
- 计算机上静音快捷键是什么,电脑静音快捷键是什么(电脑静音快捷键怎么设置)...
- sharepoint 工作经验与技能总结
- B2B企业越早做网络营销会有哪些优势 由上海添力张进老师讲解
- 无线wifi盒子用不用拉网线?
- 大数据案例--电信日志分析系统
- 论文笔记-Integration of AI activities in software development processes
- WordPress不可忽视的面包屑导航SEO优化技巧
- You are trying to add a non-nullable field 'code' to business without a default; we can't do that...
- 小程序开发+weuiwxss
热门文章
- n=sizeof(a)/sizeof(int)的含义(C语言)
- 算法:平衡二叉树110. Balanced Binary Tree
- 42表盘直径是从哪测量_万用表测量电容容量的方
- ORB feature to FAST,定向快速旋转简报
- ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any()
- pycharm 无法安装模块 nothing to show
- graphpad做饼图_超省钱的早餐攻略!这些边角料可别扔,多做一步变大餐!
- leetcode121、122、123
- 【ML小结9】聚类分析--k均值聚类
- 计算机网络超详细笔记(五):网络层