问题描述
- sql语句如何将三张表所有要的属性显示
-
SQL大神指教指教,谢谢!
表一:XS
Sno Sname Sex birthday Pid class department (表一属性)表二:CJ
Sno Courseno Score (表二属性)表三:KC
Courseno Coursename credit (表三属性)要求:"用相关查询语句"查询选修课程号为”xx“ 的学生的相关信息
解决方案
select XS.Sno, Sname,Sex, birthday, Pid, class, department,
KC.Courseno, Coursename, credit, Score
from XS
left join CJ on CJ.Sno = XS.Sno
left join KC on KC.Courseno = CJ.Courseno
解决方案二:
select x.Sno,x.Sname,x.Sex,x.birthday from XS x where x.Sno=(select c.Sno from CJ c where c.Courseno = (select k.Courseno from Coursename = "xx"))
解决方案三:
select XS.Sno,XS.Sname,XS.Sex,XS.birthday,KC. Coursename,CJ.Score
where XS.Sno=CJ.Sno and CJ.Courseno=KC.Courseno
想要显示哪个属性,在select后加就好了
解决方案四:
SELECT x.Sname from XS x where x.Sno IN
(SELECT c.Sno from CJ c where c.Courseno =
(SELECT k.Courseno from KC k where k.Coursename = "xx"));
解决方案五:
根据你的需要可以使用left join 或者 inner join
解决方案六:
我好像忘了加 from table啦 0.0
时间: 2024-11-03 08:41:59