数据库教程:MySQL的简单查询语句

查询:一:查询所有数据select * from Info 查所有数据select Code,Name from Info 查特定列二:根据条件查select * from Info where Code='p001' 一个条件查询select * from Info where Code='p00 …

查询:
一:查询所有数据
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

 

需要了解更多数据库技术:MySQL的简单查询语句,都可以关注数据库技术分享栏目—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/dtteaching/798708.html

(0)
上一篇 2021年9月12日
下一篇 2021年9月12日

精彩推荐