2 runawaysnailxxk RunawaySnailxxk 于 2016.04.11 13:37 提问

sql语句如何将三张表所有要的属性显示
sql

SQL大神指教指教,谢谢!
表一:XS
Sno Sname Sex birthday Pid class department (表一属性)

表二:CJ
Sno Courseno Score (表二属性)

表三:KC
Courseno Coursename credit (表三属性)

要求:"用相关查询语句"查询选修课程号为”xx“ 的学生的相关信息

6个回答

qq_18332445
qq_18332445   2016.04.11 14:46
已采纳

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

RunawaySnailxxk
RunawaySnailxxk 谢谢!
一年多之前 回复
u010857974
u010857974   2016.04.11 13:47
 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"))
ajfly0622
ajfly0622   2016.04.11 13:55

select XS.Sno,XS.Sname,XS.Sex,XS.birthday,KC. Coursename,CJ.Score
where XS.Sno=CJ.Sno and CJ.Courseno=KC.Courseno

想要显示哪个属性,在select后加就好了

ajfly0622
ajfly0622 加 from table
一年多之前 回复
ajfly0622
ajfly0622 select XS.Sno,XS.Sname,XS.Sex,XS.birthday,KC. Coursename,CJ.Score where XS.Sno=CJ.Sno and CJ.Courseno=KC.Courseno
一年多之前 回复
u010857974
u010857974   2016.04.11 14:06
 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"));
qq_17486399
qq_17486399   2016.04.11 14:31

根据你的需要可以使用left join 或者 inner join

ajfly0622
ajfly0622   2016.04.11 14:49

我好像忘了加 from table啦 0.0

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!