网站建设知识
初学mysql总结(2)
2025-07-22 09:58  点击: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;

今天暂时更新到这里!