MYSQL之查询

学习笔记 何锋
文章标签: MYSQL 摘抄拓展

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

二:根据条件查
select * from Info where Code='条件'     一个条件查询
select * from Info where Code='条件1' and Nation='条件2'    多条件 并关系 查询
select * from Info where Name='条件1' or Nation='条件2'         多条件 或关系 查询
select * from Car where 字段>=50 and 字段<=60 范围查询
select * from Car where 字段 between 50 and 60 范围查询

三:模糊查询
select * from 表名 where Name like '%型' %          通配符代表任意多个字符
select * from 表名 where Name like '%奥迪%' _     通配符代表任意一个字符
select * from 表名 where Name like '_马%'

四:排序
select * from 表名 order by Price asc            按照价格升序排列
select * from 表名 order by Price desc          按照价格降序排列
select * from 表名 order by Price,Oil          按照两列进行排序,前面的为主要的

五:统计函数(聚合函数)
select count(Code) from 表名        查询表中有多少条数据
select max(Price) from 表名          取价格的最大值
select min(Price) from 表名            取价格的最小值
select sum(Price) from 表名           取价格的总和
select avg(Price) from 表名            取价格的平均值

六:分组查询
select Brand from 表名 group by Brand having count(*)>2 查询所有系列中数量大于2的

七:分页查询
select * from 表名 limit 0,5 跳过几条数据取几条数据

八:去重查询
select distinct Brand from 表名

还能输出{{restrictNumber}}个字符  
  • {{reply.author}}

    {{CommonUtil.formateDate(reply.ac_CommentDate).shortTime}}
  • 回复了{{Comments.author}} :