14.相关表结构:
学生表 tb_student(编号 stuid、姓名 stuname、年龄stuage、性别 stusex)
课程表 tb_course(课程编号 courseId、课程名称 coursename、教师编号 teaid)
成绩表 tb_score(学生编号 stuid、课程编号 courseid、成绩 score)
教师表 tb_Teacher(教师编号 teaid、姓名 teaname)
(1)查询没有学全所有课的同学的学号、姓名:
select c.stuid,stuname from tb_score c join tb_student s on c.stuid=c.stuid group by a.stu_id having count(distinct courseid) <> (select count(courseid) from tb_course);
(2) 查询课程编号为“001的课程比课程编号为“002课程成绩高的所有学生的学号:
select a.stu_id,a.score score1,b.score score2 from tb_score a join tb_score b on a.stuid=b.stuid where a.score>b.score and a.corseid='001' and b.corseid='002';
(3)查询各科成绩最高和最低的分:以如下形式显示:课程名称,最高分,最低分
select corsename,max(score),min(score) from tb_course c join tb_score s on c.courseid=s.courseid group by s.courseid;
15. 根据以下两张数据表回答问题:
数据表A
编码(key) | 数据日期(ds) |
---|---|
k1 | 2009-07-07 |
K2 | 2009-07-08 |
K3 | 2009-07-07 |
K5 | 2009-07-07 |
数据表B
编码(key) | 数据日期(ds) |
---|---|
k1 | 2009-07-07 |
K2 | 2009-07-07 |
K3 | 2009-07-08 |
K4 | 2009-07-07 |
以下两个查询语句的结果分别是什么?
SELECT a. key, a. ds, b. key, b. ds FROM a LEFT OUTER JOIN b ON(a. key=b. key) WHERE a. ds=' 2009-07-07' AND b. ds='2009-07-07';
a.key | a.ds | b.key | b.ds |
---|---|---|---|
k1 | 2009-07-07 | k1 | 2009-07-07 |
SELECT a. key, a. ds, b. key, b. ds FROM a LEFT OUTER JOIN b ON(a. key=b. key AND a. dse=' 2009-07-07', AND b. ds='2009-07-07');
a.key | a.ds | b.key | b.ds |
---|---|---|---|
k1 | 2009-07-07 | k1 | 2009-07-07 |
k2 | 2009-07-08 | null | null |
k3 | 2009-07-07 | null | null |
k5 | 2009-07-07 | null | null |
16.产品入库表(ProductList)不同产品的入库时间可能相同。
入库序号(ID) | 产品名称(ProductName) | 数量(Count) | 入库时间 (DataTime) |
---|