ITPub博客

首页 > 数据库 > > 《实验题》几个SqlServer版本的SQL语句

《实验题》几个SqlServer版本的SQL语句

作者:TTT1234 时间:2023-02-21 10:20:25 0 删除 编辑

UTB_EXAM_SCORE 表有155条记录,Score是表中的一个可空字段,有103条记录非空,52条记录为空。

问:

select count(score) from UTB_EXAM_SCORE;

返回(二选一)

1、155

2、103




二、

select avg(score) from UTB_EXAM_SCORE

where

score is not null


和


select avg(score) from UTB_EXAM_SCORE


结果是否相同


三、

已知:

总成绩之和:6492.00

全部记录:155

成绩非空记录:103

总成绩/全部:41.883870

总成绩/成绩非空记录:63.029126


问:

select avg(score),SUM(score)/COUNT(1),SUM(score)/COUNT(Score)  from UTB_EXAM_SCORE

输出值:


四、

没有成绩>100的学生,故

select COUNT(1) from UTB_EXAM_SCORE where score > 100

输出0

问:

select 100/COUNT(1) from UTB_EXAM_SCORE where score > 100

执行结果


五、SQL题目

成绩为null或没有记录代表缺考

求每个班,每个科目缺考的学生人数


答案:

一、103

二、是

三、63.029126 41.883870 63.029126

四、异常

五、

select t.CourseId,COUNT(t.ID) from 

(

select s.*,c.ID as CourseId from

UTB_EXAM_STUDENT s,

UTB_EXAM_COURSE c

)t

left join

( 

select StudentId,CourseId from UTB_EXAM_SCORE where score is not null

)ts

on t.ID = ts.StudentId and t.CourseId = ts.CourseId

where 

ts.StudentId is null

and

ts.CourseId is null

group

by

t.CourseId



本文来源https://www.modb.pro/db/182146

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69953058/viewspace-3167125/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: Greenplum分区
请登录后发表评论 登录
全部评论

注册时间:2019-11-13

  • 博文量
    566
  • 访问量
    5216