今天繼續更新初學mysql,接下來下面都是關於必備的查找表的命令。使用表:student
1,查詢表全部字段數據:select * from student;
2,查詢某個字段的數據:select name from student ;
3,查詢多個字段的數據:select name ,kemu,score from student;
4,根據條件查詢(where):select * from student where scZ喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcmUmZ3Q7ODA7PGJyIC8+DQo8aW1nIGFsdD0="這裡寫圖片描述" src="http://www.bkjia.com/uploads/allimg/160403/04123SO2-3.png" title="\" />
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;
今天暫時更新到這裡!