0

我正在寻找为 2 个表创建一个视图页面,这些表是:

tbArticle:
    articleid
    name 

tbArticleMedia:
    articleid
    mediaid

我正在寻找像这样创建视图表:

viewArticleMedia:
    ArticleId         (EG vale: 1)
    ArticleName       (EG vale: this is article)
    MultimediaId      (EG vale: 1,2,3,4,5)

任何人请建议。

4

1 回答 1

0
SELECT
     a.articleId, a.Name,
     STUFF(
         (SELECT ',' + CAST(mediaid as VARCHAR(10))
          FROM  tbArticleMedia
          WHERE articleid = a.articleid
          FOR XML PATH (''))
          , 1, 1, '')  AS MultimediaId
FROM tbArticle AS a
     INNER JOIN tbArticleMedia b
        ON a.articleid = b.articleid
GROUP BY a.articleId, a.Name
于 2012-11-27T14:38:45.620 回答