肠胃病的危害:请教1个SQL阅读与书写的问题!

来源:百度文库 编辑:高考问答 时间:2024/04/29 00:32:21
给出关系模式如下:
s(sno,sname,age,sex,sdept),各属性表示学号、姓名、年龄、性别、所在系
sc(sno,cno,g),各属性表示学号、课程编号、成绩
c(cno,cname),各属性表示课程编号、课程名字
写出下列的SQL语句:
1. 查询计算机系(cs)的男生的学号、姓名
2. 查询数据库原理的平均成绩
写出下面SQL语句的意思:
1. Select sno,sname from s where s.sdept not in (select sdept from s where sno=’1001’)

请高人帮忙解答一下,谢谢!

select sno,sname from s where sdept="cs" and sex="男"

select avg(g) from sc where sc.cno in (select cno from c where cname="数据库原理")

查询与1001学号的学生不在一个系的学生学号和姓名

SELECT AVG(数据库原理) FROM sc

1.
select sno,sname from s where sedpt='cs' and sex='男';
2.
select avg(g) as avgg from sc where cno=(select cno from c where cname='数据库原理');

SQL语句的意思:
查询 s 表中 s中sdept字段不包含在后面这一结果 (查询s表中sno等于1001的值,返回sdept的结果集)的sno,sname的结果集。
简单地说,返回了所有sno不等于1001的sno,sname的结果集

大致的写了一下,没检查对错...感觉上条件给的不全,你们的sqlserver作业本意应该是要考察做联合查询的吧?把要求的条件写全了。

1. SELECT sno, sname from s where s.sex='男'
2. SELECT Avg(g) AS avgg FROM sc

意思:
查询系名不是'1001'的所有学生学号和姓名.

1. 查询计算机系(cs)的男生的学号、姓名
select sno,sname from s where sdept = cs and sex = 1
2. 查询数据库原理的平均成绩
select avg(g) as g from sc where cno in ( select * from c where cname = '数据库原理')
写出下面SQL语句的意思:
3. Select sno,sname from s where s.sdept not in (select sdept from s where sno=’1001’)
查询出与sno1001不在同一个系的学生sno,sname