MySQL的简单查询语句

查询:

一:查询所有数据

select * from Info 查所有数据
select Code,Name from Info 查特定列

二:根据条件查

select * from Info where Code='p001' 一个条件查询
select * from Info where Code='p001' and Nation='n001' 多条件 并关系 查询
select * from Info where Name='胡军' or Nation='n001' 多条件 或关系 查询
select * from Car where Price>=50 and Price<=60 范围查询
select * from Car where Price between 50 and 60 范围查询

三:模糊查询

select * from Car where Name like '%型' %通配符代表任意多个字符
select * from Car where Name like '%奥迪%' _通配符代表任意一个字符
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,Oil 按照两列进行排序,前面的为主要的

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

select count(Code) from Car 查询表中有多少条数据
select max(Price) from Car 取价格的最大值
select min(Price) from Car 取价格的最小值
select sum(Price) from Car 取价格的总和
select avg(Price) from Car 取价格的平均值

六:分组查询

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

七:分页查询

select * from Car limit 0,5 跳过几条数据取几条数据

八:去重查询
select distinct Brand from Car

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • MySQL的简单查询语句 查询: 一:查询所有数据 select * from Info 查所有数据select ...
    木易先生灬阅读 1,774评论 0 0
  • 首先需要注意的是:查询语句select再怎么操作都不会改变表中的数据!! 1、查询语句的语法格式 select 列...
    jimmywife阅读 6,572评论 0 4
  • 一如春的含苞欲放 落樱树下 纯白花嫁 黑色眸子 浅笑安然。
    无关的二月阅读 1,306评论 2 1
  • 素缎如柳月如钩, 纸上故词可堪愁。 盏中微焰芯未剪, 天涯无迹几时游? 朔风萧萧泪不休, 凭栏望雪满肩头。 一爵远...
    禾呈水原阅读 1,135评论 0 0
  • 当公平的阳光一视同仁的照耀所有的向日葵时,不是所有的向日葵都能够敞开心扉的去接受阳光照耀的,有一颗阳光心态真的很...
    2005景彦婷阅读 1,634评论 1 0

友情链接更多精彩内容