select distinct a.* from 学生表 a,课程表 b,成绩表 c
where a.学号=c.学号 and b.课程号=c.课程号
and b.课程名='计算机组成与结构' and c.成绩=100
where a.学号=c.学号 and b.课程号=c.课程号
and b.课程名='计算机组成与结构' and c.成绩=100
解决方案 »
- 请教一个链接服务器访问慢的问题
- 看看这个题,有没有高效的算法.
- ETL高手进!
- "select max(NO) as at from table1",请问at在C#中如何使用,比如如何将at赋给另一个C#整型变量ix?
- 取服务器系统时间问题
- 建立群集后,默认端口不是1433.修改正确端口号后,客户端ODBC就一定要取消"动态决定端口"才能连接
- 设计难题:领导的方案和我的方案哪种更优?
- SQL Server数据表数据量达到多大会影响查询和插入效率
- sql server中怎麼在BOM取得一個產品所有層次的物料
- 只有一个.mdf文件如何恢复数据库?
- 哪里有sql server 2000的客户端可以下载?
- 求教Sql Server2000的故障恢复问题,在线等待。谢谢。
where a.学号=c.学号 and b.课程号=c.课程号
and b.课程名='计算机组成与结构' and c.成绩=100
嵌套写法:SELECT *
FROM 学生表
WHERE (学号 IN
(SELECT 学号
FROM 成绩表
WHERE (课程号 IN
(SELECT 课程号
FROM 课程表
WHERE 课程名 = '计算机组成与结构')) AND (成绩 = 100)))嵌套执行效率较慢,建议用楼上的语句!
where 学号 in (select 学号 from 成绩表
where 课程号 = (select 课程号 from 课程表 where 课程名 = '计算机组成与结构')
and 成绩 = 100)TO:hzm_8(☆) 嵌套比连接查询要慢吗?不是说嵌套可被数据库优化吗!!!
where a.学号=c.学号 and b.课程号=c.课程号
and b.课程名='计算机组成与结构' and c.成绩=100
where 学号 in (select 学号 from 成绩表
where 课程号 = (select 课程号 from 课程表 where 课程名 = '计算机组成与结构')
and 成绩 = 100)
where 学号 in (select 学号 from 成绩表
where 课程号 = (select 课程号 from 课程表 where 课程名 = '计算机组成与结构')
and 成绩 = 100)
连接:
select students.*
from students,courses,points
where points.成绩=100 and
courses.课程名='计算机组成与结构' and
points.课程号=courses.课程号 and
points.学号=students.学号子查询:
select *
from students
where students.学号 in(select points.学号
from points
where points.成绩=100 and
points.课程号=(select courses.课程号
from courses
where courses.课程名=
'计算机组成与结构'))
select a.*
from a,b,c,
where a.学号=c.学号 and
b.课程号=c.课程号 and
b.课程名='计算机组成与结构' and
c.成绩=100子查询(嵌套):
select a.*
from a
where a.学号 in (select c.学号
from c
where c.成绩=100 and
c.课程号=(select b.课程号
from b
where b.课程名='计算机组成与结构'))
有些SQL语句既可以用连接也可以用子查询
但是,如果查询结果的列来自多个表则只能用连接;
如果中间查询结果是统计则只能用子查询。
这是我个人体会,不知对不对。
连接:
select students.*
from students,courses,points
where points.成绩=100 and
courses.课程名='计算机组成与结构' and
points.课程号=courses.课程号 and
points.学号=students.学号子查询:
select *
from students
where students.学号 in(select points.学号
from points
where points.成绩=100 and
points.课程号=(select courses.课程号
from courses
where courses.课程名=
'计算机组成与结构'))
where 学生表.学号 in
(select 成绩表.学号 from 成绩表, 课程表
where 成绩表.课程号= 课程表.课程号 and
成绩表.成绩 = 100 and
课程表.课程名 = '计算机组成与结构');