-1

我需要创建一个名为“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
4

2 回答 2

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";
于 2013-09-16T15:35:10.993 回答
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

只需将 * 替换为您需要的列。

于 2013-09-16T15:35:27.960 回答