#1) 查詢學生表中所有學生記錄
select * FROM student;
2) 查詢姓名為劉德華的學生資訊
select * from student where sname=‘劉德華’;
3) 查詢2018年入學的學生姓名、分數和入學時間
select sname, score, joindate from student where joindate like ‘2018%’;
4) 查詢專業編号為30并且分數高于80分的學生資訊
select * from student where smid=30 and score>80;
5) 查詢名字是3個字的所有學生資訊
select * from student where sname like ‘___’;
6) 查詢前4個學生的編号、姓名和入學日期
select sid, sname, joindate from student limit 4;
7) 查詢各專業的最高成績,顯示專業編号和最高成績
select smid, max(score) from student GROUP BY smid;
8) 查詢所有學生姓名及對應的專業名稱。(去除笛卡爾積)
select s.sname, m.mname from student s left join major m on s.smid=m.mid;
9) 查詢高于平均成績的學生姓名、分數和入學日期。(子查詢)
select sname, score, joindate from student where score>(select avg(score) from student);
10) 用左外連接配接(專業表為左表),查詢各專業的專業編号、專業名稱、人數。
select m.mid, m.mname, count(s.sid) from student s left join major m on s.smid=m.mid GROUP BY m.mid;