首页 > 其他 > 详细

5select的运用

时间:2018-03-04 23:26:33      阅读:196      评论:0      收藏:0      [点我收藏+]

四、select的运用

--汇总函数 max()最大值,min()最小值,avg()平均值
select max(age),min(age),avg(age) from tablename; --算出表中age的最大值,并非全部max(age)数据
select max(age),min(age),avg(age) from tablename where id!=1;

select * from tablename where max(age); --错误


--子查询 返回的是最大值
select *from tablename where age in(select max(age) from tablename);
select max(age)from tablename where age in(select max(age) from tablename);


--查询最小值到最大值之间的全部数据
select* from malestaff where age
between (select MIN(age) from malestaff) and (select MAX(age) from malestaff);

select count(*) form tablename --统计人数


--分组 根据id的不同进行分组

select * from tablename group by id;


--排序 根据id的不同进行排序,默认为升序,desc代表降序
select * from tablename order by id;
select * from tablename order by id desc;


--多种条件约束
select * from tablename
where age is not null --查询条件
group by age --分组字段 where意义等同于having
having count(*)>2 --分组条件 即相同age的人数〉2
order by count(*); --根据人数的不同,对查询数据进行升序

5select的运用

原文:https://www.cnblogs.com/gd-luojialin/p/8506749.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!