查询语句。

Posted 大脸妹?

tags:

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

select * from car where time > ‘2016-09-01‘
--模糊查询
select * from car where name like ‘奥迪%‘
--排序查询
select * from car order by oil desc --递减
select * from car order by oil asc --递增(默认)
select * from car order by oil , powers desc
--去重查询
select distinct brand from car
--分组查询
select brand from car group by brand
--聚合函数
select brand,COUNT(*) from car group by brand
select brand,AVG(oil) from car group by brand
select brand,max(oil) from car group by brand
select brand,min(oil) from car group by brand
select brand,sum(oil) from car group by brand
select brand,(max(oil)+min(oil))/2 from car group by brand

--select brand,avg(oil) from car
--group by brand having oil > AVG(oil)
--子查询

select * from car where brand in(‘b001‘,‘b002‘,‘b003‘)
select * from car where brand in(
select brand from car where name like ‘%奥迪%‘)
select * from car where price between 30 and 50
--别名
select ids as ID,code as ‘编码‘,name ‘名字‘,brand
from car


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

使用sql语句查询日期的方法

sql查询语句?

怎么用sql语句查询?

SQL查询语句

查询语言系列—JOIN 语句

SQL语句 - 嵌套查询