全國計算機二級(vf)sql語句練習2

字號:

2. 學生(學號,姓名,性別,年齡,系)
    課程(科稱號,課程名稱)
    選課(學號,課程號,成績)
    將選課在5門以上(包括5門)的學生的學號,姓名,平均分和選課門數(shù)按平均分降序排序,并將結果存于數(shù)據(jù)庫表stu_temp(字段名為學號,姓名,平均分和選課門數(shù))
    方法一:
    select 學生.學號,姓名,avg(成績) as 平均分,count(*) as 選課門數(shù) from 學生,選課;
    where 學生.學號=選課.學號;
    order by 平均分desc;
    group by 選課.學號 having count(*)>=5;
    into table stu_temp
    方法二:
    select a.學號,a.姓名,avg(b.成績) 平均分,count(b.課程號) 選課門數(shù) from 學生 a,選課 b where a.學號=b.學號 group by b.學號 having(count(b.課程號))>=5 order by 平均分 desc into dbf stu_temp