求解sql一道试题,会的答一下啊!谢了

来源:百度知道 编辑:UC知道 时间:2024/06/01 07:28:45
学生表(xh char(12),xm char(8),xb char(2),csrq datetime,bjbh char(9),zcj numeric(9))
选课表 (xh char(12),kcbh char(8),pscj numeric(9),qmcj numeric(9),kccj numeric(9))
课程表(kcbh char(8),kcmc char (30))
班级表 (bjbh char(9),bjmc char(20),bjrs int)
1.查询学生表中男生人数超过10人的班级编号,男生人数。(用分组查询)
2.查询学生表中女生人数超过 20人的班级编号、男生人数。(用分组查询)
3.根据学生表,选课表和课程表,查询出被“王杨”选修了的课程名称和成绩。
4.查询选修了课程编号为“1000092”的所有学生的姓名。(用子查询实现)
xh 学号 xm 姓名 xb 性别 csrq 出生日期 bjbh 班级编号 zcj 总成绩
kcbh 课程编号 pscj 平时成绩 qmcj 期末成绩 kccj 课程成绩
kcbh 课程编号 kcmc 课程名称
bjbh 班级编号 bjmc 班级名称 bjrs 班级人数

1.select 班级编号,count(*) from 学生表 where xb='男' group by 班级编号 having count(*)>10
2.select a.班级编号,count(*) from 学生表 a,
(select 班级编号 from 学生表 where xb='女' group by 班级编号 having count(*)>20) b
where a.班级编号=b.班级编号
and a.xb='男'
3.select c.kcmc,b.pscj,b.qmcj,b.kccj from 学生表 a,选课表 b,课程表 c
where a.xh=b.xh
and b.kcbh=c.kcbh
and a.xm='王杨'
4.select xm from 学生表 where xh in
(select xh from 课程表 where kcbh='1000092')