MySQL基礎練習

mwait發表於2021-06-13

表的一些基本操作

1.匯入sql檔案

source + 檔案位置

2.查詢某列的資料

select col1, col2, col3 from table

3.查詢所有資料

select * from table

4.查詢Score表中成績在60到80之間的所有記錄

select Degree from Score where Degree >= 60 and Degree <=80;

5.查詢Score表中成績為68,86的記錄

select Degree from Score where Degree = 68 or Degree =86;

6.查詢Student表中“9001”班或性別為“女”的同學記錄

select * from Student where Class = '9001' or Ssex = '女';

7.排序查詢

7.1 降序關鍵字desc,以Class降序查詢Student表的所有記錄

select * from Student order by Class desc;

7.2 升序:order by + colname,以Cno升序、Degree降序查詢Score表的所有記錄

select * from Student order by Cno, Degree desc;

8.查詢student表中“9002”班的學生人數

select count(Class) as '9002' from Student;

9.查詢Score表中的最高分和最低分

select max(Degree), min(Degree) from Score;

10.查詢Score表每門課的平均成績

select Sno, avg(Degree) from Score  group by Sno;

11.查詢Score表中至少有3名學生選修的,並且課程號以02結尾的課程的平均分數

select Cno, avg(Degree) from Score group by Cno

having Cno like '%02' and count(*) > 3;

相關文章