国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

SQL面試題-查詢課程

2019-11-10 17:13:51
字體:
供稿:網(wǎng)友

題目: 成績表(Grade),包含字段:GradeID(Int,自增), SNO(int, 學(xué)號), CNO(int, 課程號), Score(float,分?jǐn)?shù)) 查詢每門課程的平均(最高/最低)分及課程號; 查詢每門課程第1名的學(xué)生的學(xué)號; 查詢每門課程中超過平均分的所有學(xué)生的學(xué)號等等; 課程數(shù)據(jù)庫表 解答: 創(chuàng)建表:

Create Table Grade( GradeID int not null identity(0, 1) constraint PK_Grade PRimary key, SNO int, CNO int, Score float)Insert into dbo.Grade(SNO, CNO, Score)values(22,23,24),(32,33,44),(52,53,54),(22,23,25),(22,23,26),(22,23,27),(22,23,28),(22,23,29),(22,23,30);

1.查詢每門課程的平均(最高/最低)分及課程號:

Select AVG(Score) as AvgScore, CNO from Grade group by CNOSelect MAX(Score) as MaxScore, CNO From grade group by cno

2.查詢每門課程第1名的學(xué)生的學(xué)號:

select * from Grade a where not exists( select 1 from grade b where b.cno = a.cno and (b.score < a.score or (b.score = a.score and gradeid < a.gradeid)))

3.查詢每門課程中超過平均分的所有學(xué)生的學(xué)號:

select * from grade a where not exists( select * from(select AVG(score) avgScore, cno from grade group by cno) b where a.cno = b.cno and a.score < b.avgScore)
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 天门市| 遂溪县| 镇康县| 泰兴市| 潢川县| 松桃| 娄底市| 霍林郭勒市| 临猗县| 墨竹工卡县| 丽水市| 抚州市| 罗江县| 鹤山市| 珠海市| 嘉荫县| 包头市| 栾城县| 五原县| 都江堰市| 河池市| 依安县| 高陵县| 克东县| 化州市| 合水县| 海安县| 分宜县| 新绛县| 封开县| 宝兴县| 河北省| 荆州市| 简阳市| 平泉县| 新竹县| 曲水县| 余庆县| 石楼县| 阳新县| 搜索|