mysql 查询条件
1简单查询 select* from 表名
select name as“姓名”fromstu (把name改为名字)
2条件查询 where 后面跟条件 条件要写清楚
3模糊查询 like no like %代表任意多个字符 _代表一个字符
4排序查询 order by 字段 排序值 (desc降 asc升)
5范围查询 between....and...
6离散查询 in notin
7聚合查询 sun 求和 count数据条数 max最大值 min最小值 avg平均值
8分页查询 limit 从第几条开始,取多少数据
表名limit(pagesize-1)*5,5 pagesize是页数 *5 是每页条数 ,5 取多少条
9去重查询 distinct select distinct 表段名 from 表名
10分组查询 group by 字段 having 条件
select count(*),cno,group_concat(degree),sum(degree) from score group by cno ;
select cno,group_concat(degree),sum(degree) from score group by cno having count(*)>3
#分组之后根据条件查询使用having 不使用where
高级查询
- 连接查询,对列的扩展
Select * from student as stu,score as sc
where stu.sno = sc.sno and sc.sno = “103” ;
2.联合查询,对行的扩展
select Code,Name from Info
union
select Code,Name from Nation
3.子查询
(1)无关子查询
外层查询 (里层查询)
子查询的结果当做父查询的条件
子查询:select Code from Nation where Name='汉族'
父查询:select * from Info where Nation = ''
select * from Info where Nation = (select Code from Nation where Name='汉族')
(2)相关子查询
查询汽车表中油耗低于该系列平均油耗的所有汽车信息
父查询:select * from Car where Oil<(该系列平均油耗)
子查询:select avg(Oil) from Car where Brand = '某个系列'
select * from Car a where Oil<(select avg(Oil) from Car b where b.Brand = a.Brand )
mysql 查询条件的更多相关文章
- mysql 查询条件中文问题
这是mysql字符编码的问题,因为mysql默认的字符编码为latin1它并不识别中文,所以在读取查询语句时会出现乱码 从而使查询条件不正确所以我们只需要更改它的字符编码就可以一般都是用utf8 这里 ...
- 字符串变量作mysql查询条件
原文:http://blog.csdn.net/qing_gee/article/details/41646503 当你的查询条件是一个字符串变量时,你该怎么办,比如字符串可能是“0001ME,000 ...
- 转!!mysql 查询条件不区分大小写问题
做用户登录模块时,输入用户名(大/小写)和密码 ,mysql都能查出来.-- mysql查询不区分大小写. 转自 http://blog.csdn.net/qishuo_java/article/de ...
- mysql 查询条件 默认不区分大小写
mysql查询默认是不区分大小写的 如: 1 2 select * from some_table where str=‘abc'; select * from some_table where st ...
- mysql 查询条件不区分大小写问题
转自 http://blog.csdn.net/qishuo_java/article/details/40118937 转自 https://www.cnblogs.com/wuyun-blog/p ...
- Mysql 查询条件中字符串尾部有空格也能匹配上的问题
一.表结构 TABLE person id name 1 你 2 你(一个空格) 3 你(二个空格) 二.查询与结果 select * from person where `name` = ? 无论 ...
- 字符串型MySQL查询条件需要注意的一点
最近在工作中遇到了数据库服务器产生很多读写队列的问题,于是要求大家开始优化我们的SQL语句. 下面是查询quotedata_history表中的code字段的SQL语句,其中code字段的类型是var ...
- mysql查询条件字段值末尾有空格的问题
mark MYSQL的binary解决mysql数据大小写敏感问题的方法
- mysql 关联条件与查询(过滤)条件
mysql用outer join时 on 后边只是关联条件,有时可能会查出无用的记录, 需用where查询条件过滤 五欧诺个的数据. 记录一下
随机推荐
- Druid.io系列(七):架构剖析
1. 前言 Druid 的目标是提供一个能够在大数据集上做实时数据摄入与查询的平台,然而对于大多数系统而言,提供数据的快速摄入与提供快速查询是难以同时实现的两个指标.例如对于普通的RDBMS,如果想要 ...
- 如何实现session共享
http://www.cnblogs.com/xiehuiqi220/p/3592300.html 首先我们应该明白,为什么要实现共享,如果你的网站是存放在一个机器上,那么是不存在这个问题的,因为会话 ...
- Cocos2d-html5帧动画
单独获取plist里面一个文件: cc.SpriteFrameCache.getInstance().addSpriteFrames(s_test_plist); var spriteTest2 = ...
- Spring中引质增强的安全
在引质增强中使用ThreadLocal变量,是因为控制状态使代理类变成了非线程安全的实例,为了解决单线程安全的问题,通过ThreadLocal让每个线程单独使用一个状态.
- Swift 修改UITextField.Placeholder颜色
StoreNameEditTextField.attributedPlaceholder = NSAttributedString(string:"点此处输入门店名称",attri ...
- C# Graphics中有关绘图质量的几个Mode
一.CompositingMode 获取一个值,该值指定如何将合成图像绘制到此 Graphics.复合模式确定从源映像的像素是覆盖(SourceCopy)还是组合(SourceOver, 需要使用半透 ...
- Halcon中循环读取文件的实现以及数字与字符的转换
在循环读取文件的位置时,常用到数字与字符的转换. 数字与字符的转换 将字符转换为数字 tuple_number(StringImageIndex,IntImageIndex)` 1 2 1 2 将数字 ...
- leetcode513
/** * Definition for a binary tree node. * public class TreeNode { * public int val; * public TreeNo ...
- application-defined exception
dataSnap服务器,客户端调用的时候写错了一句话, SQLConnection1->CloneConnection(); 改为 SQLConnection1->Close(); 就好了 ...
- SpringBoot入门之spring-boot-maven-plugin
spring-boot-maven-plugin插件是将springboot的应用程序打包成fat jar的插件.首先我们说一下啥叫fat jar.fat jar 我们暂且叫他胖jar吧,实在是找不到 ...