-1

我有三张桌子。设计就像

学生桌

create table student (studID int not null primary key AUTO_INCREMENT,
StudName varchar(20),
Parent varchar(20),
PhoneNo int not null
)

课桌设计

create table Course (CID int not null primary key AUTO_INCREMENT,
CName varchar(20))

stud课程表设计

create table studCourse(studID int not null
,CID int not null
)

我如何制作一个显示学生姓名和他正在学习的课程的视图?

4

2 回答 2

0
  CREATE VIEW vwStudent  AS
       SELECT
      s.StudName,
      c.CName
    FROM student s
      INNER JOIN studCourse sc
        ON s.studID = sc.studID
      INNER JOIN Course c
        ON c.CID = sc.CID

或者

 CREATE VIEW vwStudent  AS

    SELECT
          s.StudName,
          c.CName
        FROM student s
          JOIN studCourse sc
            ON s.studID = sc.studID
          JOIN Course c
            ON c.CID = sc.CID

试试这个

于 2012-04-09T08:38:54.573 回答
0

您可以使用 JOIN 从查询中创建视图,这样应该可以工作:

CREATE VIEW v AS (
SELECT s.StudName AS student,c.CName AS course  
FROM student s
JOIN studCourse d USING(studID)
JOIN Course c ON (d.CID = c.CID)
)
于 2012-04-09T08:39:26.040 回答