MySQL的简单查询语句

2018-09-27  本文已影响0人  木易先生灬

MySQL的简单查询语句

查询:

一:查询所有数据

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

二:根据条件查

select * from Info where Code='p001' 一个条件查询
select * from users order by ctime desc 根据时间倒序查询
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 表名 order by ctime desc limit 10,10; // 先按时间排序,然后跳过10调数据,取后10条数据

三:模糊查询

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

九: 删除

delete from 表名; //删除全部
delete from 表名 where id=1; //删除id 为 1的数据

十: 修改数据

updatte 表名 set 字段名=值 where id=1;//修改id为1数据的 字段的值;

上一篇 下一篇

猜你喜欢

热点阅读