码迷,mamicode.com
首页 > 数据库 > 详细

初学mysql 总结(2)

时间:2016-03-27 01:45:55      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:

今天继续更新初学mysql,接下来下面都是关于必备的查找表的命令。使用表:student
1,查询表全部字段数据:select * from student;
技术分享
2,查询某个字段的数据:select name from student ;
技术分享
3,查询多个字段的数据:select name ,kemu,score from student;
技术分享
4,根据条件查询(where):select * from student where score>80;
技术分享
5,根据多个条件查询(where …and ..):select * from student where kemu=’PE’ and score>80;
技术分享
6,根据首字母为j的名字的学生查询:select * from student where name like ‘j%’;
技术分享
7,根据学生的分数进行排序(升序ASC,降序DESC)查询(order by):select * from student order by score asc;
技术分享
8,根据关键字(in)查询:select * from student where id in (1,2,3);
技术分享
9,查询分数的区间(between and ):select * from student where score between 80 and 90;
技术分享
10,查询分数不重复的数据(distinct):select distinct name ,score from student;
技术分享
11,分组查询(group by): select * from student group by name;
技术分享
12,限制查询结果的数量(limit) :select * from student order by asc limit 5;
技术分享
13,使用常用函数count()查询,好处:若查询字段有null,不会查询出来:
select count(*) from student;
技术分享
14,使用常用函数sum()求总和 :select sum(score) from student;
技术分享
15,使用常用函数avg()求平均值:select avg(score) from student;
技术分享
16,使用常用函数min()求最小值,max()求最大值:
select max(score),min(score) from student;
技术分享

今天暂时更新到这里!

初学mysql 总结(2)

标签:

原文地址:http://blog.csdn.net/johndeng520/article/details/50989278

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!