如何簡單運用好 select * from語句,在不同的函數下,有不同的先后順序。
語法格式 (代表先后順便)
(2)select 字段名 查詢什么東西
(1)from 表名,從哪個表查詢
例如:查詢所有學生姓名
select name
from stu;
(3)select 字段名 查詢什么東西
(1)from 表名,從哪個表查詢
(2)where 表達式,條件 要通過什么來查詢
例如:查詢所有女學生的信息
select *
from stu
where sex ='女';
(3)select 字段名 查詢什么東西
(1)from 表名,從哪個表查詢
(2)where 表達式,條件 要通過什么來查詢
(4)order by 字段名 or desc/asc 降序和升序,默認是升序
查詢選修了課程編號為‘105‘的學生的學生編號,成績,結果以降序排列
select student_no,grade
from sc
where course_no ='105' order by grade desc;
(4)select 字段名 查詢什么東西
(1)from 表名,從哪個表查詢
(2)where 表達式,條件 要通過什么來查詢
(3) group by 字段名 (having函數)
(5)order by 字段名 or desc/asc 降序和升序,默認是升序
查詢各個課程編號及相應的選課人數
select course_no,count(student_no)
from sc
group by counrse_no;
查詢選修2門以上課程的學生學號
select student_no
from sc
group by student_no
having count(course_no)>2;