简单查询

Posted FTHeD

tags:

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

简单查询
1查询所有数据
selete * from info
2查询指定列
select code,name from info
3给列指定名称
select code as ‘代号‘,name as ‘姓名‘ from info
4条件查询
select * from info where code=‘p001‘
5模糊查询:根据关键字查询
select * from car where name like ‘_奥迪_‘ %百分号奥迪前面可以有N个字符,可以后面有N个字符;_下滑线只能出现一个字符,
6排序查询
select * from car order by price desc,oil desc
代表以价格进行排序,price后面不加,默认升序排列,降序使用desc;price是第一优先级排序,如果价格相等则oil排序
7去重查询
select distinct brand from car
8分页查询
select * from car limit 5,5
跳过几条,取几条
9统计查询或聚合函数
select count(*) from car查询出多少条数据
取最大值
select max(price) from car
取最小值
select min(price) from car
取平均值
select avg(price) from car
分组查询
select brand,count(*) from car group by brand
select brand from car group by brand having count(*)>=3
范围查询
select * from car where price>=40 and price<=60
select * from car where price between 40 and 60
离散查询
select * from car where price in(10,20,30,40)在里面出现
select * from car where price not in(10,20,30,40)不在里面出现
联合查询
union
连接查询
形成笛卡尔积

 

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

T-SQL简单查询语句(模糊查询)

数据库单表查询 - 简单筛选查询

数据查询,简单查询及高级查询

为啥 EF 为简单查询生成子查询?

MySQL数据表简单查询

7-12简单子查询