学生表student(stu_id,stu_name),班级表class(monitor_id,vince_monitor_id) monitor_id为正班长学号,vince_monitor_id为副班长学号,而且monitor_id为student外键,vince_monitor_id也为student外键
用一条SQL查询语句,怎样查出一个班上正班长姓名和副班长姓名?

解决方案 »

  1.   


    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
      

  2.   

    select * from student as s left jion class as c on s.stu_id = c.monitor_id or s.stu_id = vince_monitor_id
      

  3.   

    select a.stu_name ,b.stu_name
    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
      

  4.   


    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
      

  5.   

    select 
    正班长姓名=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
      

  6.   


    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