45题的难点

1.以Cno升序、Degree降序查询Score表的所有记录。
select *from score order by cno asc,degree desc

2.查询Score表中至少有5名学生选修的并以3开头的课程的平均分数。
select avg (degree) as ‘平均分‘from score where cno in(
select cno from score group by cno having COUNT(*)>5 and cno like ‘3%‘)

3.表连接,在没有共同列时可以进行列与列的比较

ps:select sno,cno,degree,[RANK] from score,grade where degree>low and degree <upp

4.查询score中选学多门课程的同学中分数为非最高分成绩的记录
select *from score where degree <(select MAX(degree)from score where sno in(select sno from score group by sno having COUNT(*)>1))
and sno in (select sno from score group by sno having COUNT(*)>1)

5.查询选修某课程的同学人数多于5人的教师姓名。

select tname from teacher where tno in(select tno from course where cno in (select cno from score group by cno having COUNT(*)>5))

6.查询选修编号为“3-105“课程且成绩至少高于选修编号为“3-245”的同学的Cno、Sno和Degree,并按Degree从高到低次序排序。

select cno,sno,degree from score where cno=‘3-105‘and degree >any(select degree from score where cno=‘3-245‘)order by degree asc

7.查询成绩比该课程平均成绩低的同学的成绩表。
select * from score as a where degree<all(select avg(degree)from score as b where a.cno=b.cno)

8.查询至少有2名男生的班号。
select class from student where ssex =‘男‘ group by class having COUNT(*)>=2

9.以班号和年龄从大到小的顺序查询Student表中的全部记录。
select *, YEAR(GETDATE())-YEAR(sbirthday)as ‘年龄‘ from student order by class , YEAR(GETDATE())-YEAR(sbirthday) desc

注意:having 就是group by 的where条件,对group by生成的结果进行筛选,只能跟聚合函数        

        sql里面as可以简单的理解为重命名,as a对表、对列起别名,起别名就是抓过前面的表过来用

时间: 2024-08-14 00:18:01

45题的难点的相关文章

php 查询45题

表格代码 create table student ( sno varchar(20) primary key, sname varchar(20) not null, ssex varchar(20) not null, sbirthday datetime, class varchar(20) ) ; create table teacher ( tno varchar(20) primary key, tname varchar(20) not null, tsex varchar(20)

SQL server 45题

use mydb create table Student ( Sno char(3) not null primary key, Sname char(8) not null, Ssex char(2) not null, Sbirthday datetime, Class char(5) ) create table Teacher ( Tno char(3) not null primary key, Tname char(4) not null, Tsex char(2) not nul

你不知道的JavaScript--Item31 值得你挑战的JavaScript面试题(45题)

你不知道的JavaScript系列,已经有这么多篇博文了,今天找了一些题目,我觉得,下面这些是你"不可能全部会做 " 的javascript题目,不信你可以试试,答案在后面的博客给出,也许你是jser大神,欢迎挑战一下! 给答对一半以上的同学点10086个赞!!!!!!双十一的夜晚,和你们一起High起来!!!!!!!!!!!!!!!!!! 1,以下表达式的运行结果是: ["1","2","3"].map(parseInt)

SQL server 练习查询45题(18-45)及笔记4

--18. 假设使用如下命令建立了一个grade表: create table grade(low int,upp int,rank char(1)) insert into grade values(90,100,'A') insert into grade values(80,89,'B') insert into grade values(70,79,'C') insert into grade values(60,69,'D') insert into grade values(0,59

你不知道的JavaScript--值得你挑战的JavaScript面试题(45题)

1,以下表达式的运行结果是: ["1","2","3"].map(parseInt) A.["1","2","3"] B.[1,2,3] C.[0,1,2] D.其他 1 2 3 4 5 6 7 8 9 2,以下表达式的运行结果是: [typeof null, null instanceof Object] A.["object",false] B.[null,fal

【ocp-12c】最新Oracle OCP-071考试题库(45题)

45.(9-16)choose the best answer: View the Exhibit and examine the data in the EMPLOYEES table. You want to generate a report showing the total compensation paid to each employee to date(迄今为止支付给每位员工的总补偿). You issue the following query: SQL>SELECT enam

sql练习45题

teacher-course-sc-student 1.查询" 01 "课程比" 02 "课程成绩高的学生的信息及课程分数 1.1 查询同时存在" 01 "课程和" 02 "课程的情况 select a.sid, a.cid, a.score as "01", b.score as "02" from sc a inner join sc b on a.sid = b.sid and a

SQL表操作习题6 36~45题

SQL server 练习查询45题(1-17)及笔记 3

create table student ( Sno int primary key not null,--设置主键 Sname varchar(50)not null, Ssex varchar(50)not null, Sbirthday date , Class varchar(50), ) insert into student values(108,'曾华','男','1977-09-01',95033)--插入信息 insert into student values(109,'王芳