学生表student(stu_id,stu_name),班级表class(monitor_id,vince_monitor_id) monitor_id为正班长学号,vince_monitor_id为副班长学号,而且monitor_id为student外键,vince_monitor_id也为student外键
用一条SQL查询语句,怎样查出一个班上正班长姓名和副班长姓名?
用一条SQL查询语句,怎样查出一个班上正班长姓名和副班长姓名?
解决方案 »
- 查询结果在类型不兼容问题
- 请教!如果字典表中的数据改变,而对应的其它表中又要能显示以前的数据,如何设计?
- SQL排序问题
- sql2005分区后,进行分区查询反而比普通查询慢好多,不知道什么原因(分区过程中没有错误)
- 做交叉表存储过程的时候因为列数超长造成错误,怎么办?有难度的问题!!从结构上怎么改?
- 这样一个SQL语句的索引应该怎么建
- 请问怎样将分类汇总的结果插入到表中
- 求助-如何将存储在sql server2000上的数据库转移到MySQL中 ?
- 这样的sql语句怎么写?
- 运行select提示错误:LOB 数据类型节点的数据库 ID 11 (页 (1:3789),槽 67)不存在
- 这种咋弄的,以前看到过,忘了!!!!
- 求一sql语句
select 正班长姓名=b.stu_name,副班长姓名=c.stu_name
from class a
left join student b on a.monitor_id=b.stu_id
left join student c on a.vince_monitor_id=c.stu_id
from class c
left join student a on a.stu_id = c.monitor_id
left join student b on b.stu_id = c.vince_nonitor_id
select [id]=monitor_id,stu_name from student s,class c where c.monitor_id=s.stu_id
union all
select [id]=vince_monitor_id,stu_name from student s,class c where c.vince_monitor_id=s.stu_id
正班长姓名=b.stu_name,
副班长姓名=c.stu_name
from class a
join student b on a.monitor_id=b.stu_id
join student c on a.vince_monitor_id=c.stu_id
select
正班长姓名=b.stu_name,
副班长姓名=c.stu_name
from
class a,student b ,student c
where
a.monitor_id=b.stu_id
and
a.vince_monitor_id=c.stu_id