我现在有student(学生)表,music(音乐班)表,sport(体育班)表,dance(舞蹈班)表,其中music,sport,dance这三张表中都有一个引用学生表主键的外键,我现在想查询一个学生都参见了哪些班,sql语句怎么写啊。谢谢

解决方案 »

  1.   

    select * 
    from student as a
    left join music as b on a.stuID = b.stuID 
    left join sport as c on a.stuID = c.stuID 
    left join dance as d on a.stuID = d.stuID 
    where stuName = @StuName
      

  2.   


    select * from music where music.id=特定学生id
    union
    select * from sport where music.id=特定学生id
    union
    select * from dance where music.id=特定学生id
      

  3.   

    select name,
      decode((select count(*) from music where stuid=student.name),0,'没参加','参加') music ,
      decode((select count(*) from sport where stuid=student.name),0,'没参加','参加') sport,
      decode((select count(*) from dance where stuid=student.name),0,'没参加','参加') dance
     from student