>查询:

一.查询所有数据:

select * from Info    ---查询所有数据(行)

select Name from Info  ---查询特定列(Name列)

select Name,Code from  Info ---查询特定两列(Name和Code列)

二.根据条件查

select * from  Info  where Code='p001'           一个条件查询(遍历每一个数据查出来的)

select * from Info  where  Code='p001' and  Nation='n003'       多条件 并关系  查询

select * from  Info where  Name='胡军'  or  Nation='n001'         多条件  或关系  查询

select * from  Car  where  Price  >=50  and <=60     范围查询(可以用,不建议)

select * from  Car where  Price between 50  and  60   范围查询(推荐)

三. 模糊查询(也属于条件查询,模糊查询是针对字符串查询)

select * from Car  where Name like '%奥迪'     ----%是通配符,代表任意N个字符

select * from Car where Name like '%奥迪%'    ---代表着在Name中只要有奥迪这个字符串就可以   前后都可以有N个字符串

select * from Car where Name like '_奥迪'       _通配符:代表任意一个字符

四.排序

select * from Car  order by  Price (asc)    按照价格升序排列(默认的是升序排列)

select * from Car order  by Price desc    按照价格降序排列

select * from Car  order by Price desc ,Oil desc   (  谁写在前面先排谁)   按照两列进行排序,前面的为主要的

五. 统计函数(聚合函数)

select count(Code)  from Car      查询表中有多少条数据

//如果括号里的是*,那么就遍历每一条每一列数据;如果括号里是Code,那么就只看Code里的数据,如果有数据,就算一个;为了执行更快一些,一般用主键

select max(Price) from Car       取价格的最大值

select min(Price) from Car        取价格的最小值

select sum(Price) from Car       取价格的总和

select avg(Price) from Car        取价格的平均值

六.分组查询

select * from Car  group by Brand  →   select Brand from Car group by Brand → select count(Brand) from Car group by Brand

select  Brand from Car group by Brand having conut(*)>2    查询所有系列中数量大于2的

七.分页查询

select * from Car  limit 5,5       跳过几条(前面的参数)数据取几条数据 (后面的参数)

select  top5 from Car    (在sql server中表示取前五条数据,但是在MySQL中不能使用)

八.去重查询

select distinct  from  Brand from Car    (只保留第一个)

最新文章

  1. Python 学习手册, char 14 - 15
  2. QuartZ Cron表达式
  3. 实现tableview的下拉刷新
  4. TinyXML:一个优秀的C++ XML解析器
  5. epoll中et+多线程模式中很重要的EPOLL_ONESHOT实验
  6. Hadoop作业JVM堆大小设置优化 [转]
  7. run.do 文件编写说明
  8. poj 2485 Highways(最小生成树,基础,最大边权)
  9. Kafka 0.8: 多日志文件夹机制
  10. mouseover,mouseout和mouseenter,mouseleave
  11. php 中PHP_EOL使用
  12. UNIX环境高级编程——TCP/IP网络编程
  13. Python距离放弃拉近的day03
  14. Effective java ---遵守普遍接受的命名规则
  15. Vuex以及axios
  16. MySQL5.7版本及以上,改密码sql语句;grant创建用户已经密码
  17. Python学习——多线程,异步IO,生成器,协程
  18. Linux驱动的两种载入方式过程分析
  19. docker中,将容器中的文件拷贝到宿主机上
  20. Codeforces 960D - Full Binary Tree Queries

热门文章

  1. 系统休眠消息PBT_APMSUSPEND
  2. ajax,文件上传,分页器
  3. python 方法无法在线程中使用(附python获取网络流量)
  4. [UWP]从头开始创建并发布一个番茄钟
  5. Java学习笔记——I/O流常用类之间的继承关系及构造方法
  6. rbash限制用户执行的命令
  7. 数据库root密码删除
  8. TCP/IP网络协议
  9. HDU 1007:Quoit Design(分治求最近点对)
  10. C++学习书籍推荐《C++ Primer 第四版》下载