<i id='yDeNw'><tr id='yDeNw'><dt id='yDeNw'><q id='yDeNw'><span id='yDeNw'><b id='yDeNw'><form id='yDeNw'><ins id='yDeNw'></ins><ul id='yDeNw'></ul><sub id='yDeNw'></sub></form><legend id='yDeNw'></legend><bdo id='yDeNw'><pre id='yDeNw'><center id='yDeNw'></center></pre></bdo></b><th id='yDeNw'></th></span></q></dt></tr></i><div id='yDeNw'><tfoot id='yDeNw'></tfoot><dl id='yDeNw'><fieldset id='yDeNw'></fieldset></dl></div>
  1. <tfoot id='yDeNw'></tfoot>

    • <bdo id='yDeNw'></bdo><ul id='yDeNw'></ul>

    <small id='yDeNw'></small><noframes id='yDeNw'>

  2. <legend id='yDeNw'><style id='yDeNw'><dir id='yDeNw'><q id='yDeNw'></q></dir></style></legend>

      MySQL 创建视图连接两个表

      MySQL create view joining two tables(MySQL 创建视图连接两个表)

        • <tfoot id='C3PGe'></tfoot>
        • <small id='C3PGe'></small><noframes id='C3PGe'>

          1. <legend id='C3PGe'><style id='C3PGe'><dir id='C3PGe'><q id='C3PGe'></q></dir></style></legend>
              <bdo id='C3PGe'></bdo><ul id='C3PGe'></ul>
                <i id='C3PGe'><tr id='C3PGe'><dt id='C3PGe'><q id='C3PGe'><span id='C3PGe'><b id='C3PGe'><form id='C3PGe'><ins id='C3PGe'></ins><ul id='C3PGe'></ul><sub id='C3PGe'></sub></form><legend id='C3PGe'></legend><bdo id='C3PGe'><pre id='C3PGe'><center id='C3PGe'></center></pre></bdo></b><th id='C3PGe'></th></span></q></dt></tr></i><div id='C3PGe'><tfoot id='C3PGe'></tfoot><dl id='C3PGe'><fieldset id='C3PGe'></fieldset></dl></div>
                  <tbody id='C3PGe'></tbody>

                本文介绍了MySQL 创建视图连接两个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                如何创建将不同列与不同表合并的视图?例如我有三个表:用户、物品和礼物(在这个例子中是一个用户可以向另一个用户赠送礼物的系统)

                How can I create a view that merges different columns with a different table? I have three tables for example: users, items and gifts (in this example it's a system that a user can give a gift to another user)

                users 表包含有关用户的信息,items 表包含有关项目的信息,gifts 表显示哪个用户向哪个用户发送了什么礼物.

                users table has information about users, items table has information about items and gifts table shows which user sent what gift to which user.

                我想要的是创建一个如下所示的视图:

                What I want is to create a view like following:

                user_from | user_to | gift_name  | gift_price
                sally     | john    | Teddy Bear | 10
                

                推荐答案

                必须先连接三个表.示例

                You must join the three tables first. Example

                CREATE VIEW GiftsList
                AS
                SELECT  b.name user_from,
                        c.name user_to,
                        d.name gift_name,
                        d.price gift_price
                FROM    gift a
                        INNER JOIN users b
                            ON a.user_from = b.id
                        INNER JOIN users c
                            ON a.user_from = c.id
                        INNER JOIN items d
                            ON a.item = d.id
                

                这篇关于MySQL 创建视图连接两个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)
                MySQL GROUP BY DateTime +/- 3 seconds(MySQL GROUP BY DateTime +/- 3 秒)
                MySQL cumulative sum grouped by date(按日期分组的 MySQL 累计总和)

                  <small id='N1ebh'></small><noframes id='N1ebh'>

                    <tbody id='N1ebh'></tbody>

                    <tfoot id='N1ebh'></tfoot>
                    <i id='N1ebh'><tr id='N1ebh'><dt id='N1ebh'><q id='N1ebh'><span id='N1ebh'><b id='N1ebh'><form id='N1ebh'><ins id='N1ebh'></ins><ul id='N1ebh'></ul><sub id='N1ebh'></sub></form><legend id='N1ebh'></legend><bdo id='N1ebh'><pre id='N1ebh'><center id='N1ebh'></center></pre></bdo></b><th id='N1ebh'></th></span></q></dt></tr></i><div id='N1ebh'><tfoot id='N1ebh'></tfoot><dl id='N1ebh'><fieldset id='N1ebh'></fieldset></dl></div>
                        • <bdo id='N1ebh'></bdo><ul id='N1ebh'></ul>

                          <legend id='N1ebh'><style id='N1ebh'><dir id='N1ebh'><q id='N1ebh'></q></dir></style></legend>