简单查询

范围查询:

select * from 表名 where price>40 and price<80     select * from 表名 where price  between 40 and 80

离散查询:

 select * from 表名 where price=30 or price=40 or price=50;

 select * from 表名 where price in(30,40,50); 

select * from 表名 where price not in(30,40,50);

聚合函数(统计查询)

select count(*) from 表名||select count(主键) from 表名#取所有的数据条数;

select sum(列名) from 表名#求总和;select avg(列名) from 表名#求平均值

select max(列名) from 表名#求最大值;select min(列名) from 表名#求最小值;

分页查询:

select * from 表名 limit 0,10#跳过0条取10条;

规定每页显示的条数:m  当前页数:n   select * from 表名 limit (n-1)*m,m

去重查询:

select distinct 列名 from 表名

分组查询:

select 列名,count(*) from 表名 group by 列名#分组完后只能查询该列或聚合函数

select 列名 from 表名 group by 列名 having avg (列名1)>40#取该系列价格平均值大于40的系列代号

 

posted @ 2016-10-17 10:13  学生Q  阅读(145)  评论(0编辑  收藏  举报