从SQL中的多个表中选择 [英] Select from multiple tables in sql

查看:396
本文介绍了从SQL中的多个表中选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我在选择语句中联接数据库的表时遇到问题.
我在数据库中创建了3个表.这是我的桌子:
具有列{ID,名称,类型}的表人员"
(//ID为主键,类型为nvarchar,其值为"teacher"或"student")
具有列{TID,Course}的表教师"////TID是Persons.ID
的外键 具有列{SID,Grade}的表学生"//SID是Persons.ID
的外键

现在,我要选择人员"的所有列,并增加一个新列,其内容将由类型"列确定.如果Type是Teacher,则检索Teacher表的"Cource"列的值;如果Type是Student,则检索Student表的Grade列的值.我的select语句应该如何?希望你明白我的意思.
感谢您的帮助.

Hi I have a problem to joinig Tables of my database in select statement.
I created 3 table in my database . here is my table :
Table ''Persons'' with column{ID , Name,Type}
(//ID is primary key , Type is nvarchar with value of ''teacher'' or ''student'')
Table ''Teachers'' with column{TID,Course} //TID is foreign key for Persons.ID
Table ''Student'' with column{SID,Grade} //SID is foreign key for Persons.ID


Now I want to select all column of Persons with extra new column wich it''s content will be determined by column ''Type''. if Type is teacher it retrieve value of column ''Cource'' of Teacher table and if Type is Student it retrieve value of column Grade of Student table . How my select statement.I should be ? hope you understand what I mean .
Thanks for your help.

推荐答案

您是否意识到无法将学生与课程联系起来?当然,他有一个成绩,但是它是做什么用的?
Did you realize that you have no way to associate a student with a course? Sure, he has a grade, but what course is it for?


这篇关于从SQL中的多个表中选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆