数据库简单查询

Posted 所爱隔山隔海

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数据库简单查询相关的知识,希望对你有一定的参考价值。

1、最简单查询:

select * from car;

2、查询制定列:

select name oil,powers from car;

3、对查出的列名修改名字:

select name as ‘车名‘,oil as ‘油耗‘,powers as ‘动力‘ from car;

4、按条件查询:

select name,oil,powers from car where oil = 8.7;

5、多条件查询:

select name,oil,powers from car where oil = 8.7 or powers = 160;
select name,oil,powers from car where oil = 8.7 and powers = 160;

6、范围查询:

select * from car where price>=40 and price <=60;
select * from car where price between 40 and 60;

7、离散查询:

select * from car where powers = 130 or powers = 150 or powers = 170;
select * from car where powers in (130,150,170);
select * from car where powers not in (130,150,170);

8、模糊查询:

select * from car where name like ‘%宝马%‘;
select * from car where name like ‘_宝马%‘;

9、排序查询:  asc 升序 desc 降序    order by

select * from car order by oil asc;
select * from car order by brand asc,price desc;

10、去重复查询:  distinct

select distinct brand from car;

11、分页查询:

select * from car limit 5,5;
n;m = 5;
limit (n-1)*m,m;   【补充】

12、聚合函数查询:

count(列名) sum(列名) avg(列名) max(列名) min()
select count(*) from car;
select sum(price) from car;
select avg(price) from car;
select max(price) from car;
select min(price) from car;

 

 

 

以上是关于数据库简单查询的主要内容,如果未能解决你的问题,请参考以下文章

MySQL数据表简单查询

数据库原理与应用实验3--(数据库的简单查询和连接查询)

数据库部分---查询-简单查询;

数据库简单查询

用SQL完成查询,设有一个简单的教学管理数据库,其关系模式为:

Oracle数据库之四 简单查询