我需要创建一个名为“testdisplay”的视图,该视图显示作者,文章和文章类别。
但是,我无法创建视图以获得所需的结果。我已经提供了下表的详细信息:
DESCRIBE ArticleAuthors;
Field Type Null Key Default Extra
AuthorCode int(11) NO PRI NULL auto_increment
FirstName varchar(100) NO NULL
LastName varchar(100) NO NULL
EmailAddress varchar(100) NO NULL
Bio_Info varchar(250) NO NULL
DESCRIBE Articles;
Field Type Null Key Default Extra
ArticleCode int(11) NO PRI NULL auto_increment
AuthorCode int(11) NO NULL
Title varchar(100) NO MUL NULL
ShortDescription varchar(250) NO MUL NULL
ArticleText varchar(500) NO MUL NULL
date date NO NULL
DESCRIBE ArticleCategories;
Field Type Null Key Default Extra
ArticleCategoryCode int(11) NO PRI NULL auto_increment
ArticleCode int(11) NO NULL
Category varchar(100) NO NULL
答案 0 :(得分:1)
创建视图,然后从视图中进行查询。
Create View `testdisplay` as
Select
a.FirstName author, ar.Title article, c.Category Category
From
ArticleAuthors a
join Articles ar on ar.AuthorCode=a.AuthorCode
join ArticleCategories c on c.ArticleCode=ar.ArticleCode;
从视图中选择的示例:
select * from testdisplay where author = "your favorite author";
答案 1 :(得分:1)
CREATE VIEW testdisplay as
SELECT * FROM Articles art JOIN ArticleAuthors aut
ON art.AuthorCode=aut.AuthorCode
JOIN ArticleCategories cat
ON art.ArticleCode=cat.ArticleCode
只需将*替换为您需要的列。