<tfoot id='y7j9k'></tfoot>
        <bdo id='y7j9k'></bdo><ul id='y7j9k'></ul>
      1. <small id='y7j9k'></small><noframes id='y7j9k'>

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

        将一个表中的多列连接到另一表中的单列

        Join multiple columns from one table to single column from another table(将一个表中的多列连接到另一表中的单列)

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

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

                • <bdo id='jdm6n'></bdo><ul id='jdm6n'></ul>
                  本文介绍了将一个表中的多列连接到另一表中的单列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试学习如何将一个表中的多列连接到另一个表中的单列.

                  I'm trying to learn how to join multiple columns from one table to a single column from another table.

                  这是我最简单的表格结构:

                  团队

                  id | team_name |
                  1  |   teamA   |
                  2  |   teamB   |
                  3  |   teamC   |
                  4  |   teamD   |
                  

                  交易

                  id |  team_1 (FK to teams.id)  |  team_2 (FK to teams.id)  |
                  1  |            1              |              2            |
                  2  |            3              |              4            |
                  

                  这是我当前将trades.team_1 连接到teams.id 的SQL:

                  SELECT teams.team_name AS team1, teams.team_name AS team2, trades.team_1, trades.team_2
                  FROM teams
                  JOIN trades ON (trades.team_1 = teams.id);
                  

                  我的问题是,如何创建第二个连接,同时将 trades.team_2 连接到 trades.id?

                  这意味着trades.team_1和trades.team_2都将加入trades.id

                  This would mean both trades.team_1 AND trades.team_2 would be joined to trades.id

                  我想要返回的结果是:

                  team1  |  team2  |  team_1  |  team_2  |
                  teamA  |  teamB  |    1     |     2    |
                  teamC  |  teamD  |    3     |     4    |
                  

                  推荐答案

                  像这样:

                  select t1.team_name as team1, t2.team_name as team2, t.team_1, t.team_2
                  from trades t
                  inner join teams t1 on t1.id = t.team_1
                  inner join teams t2 on t2.id = t.team_2;
                  

                  这篇关于将一个表中的多列连接到另一表中的单列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Building a comma separated list?(建立一个逗号分隔的列表?)
                  Errors in SQL Server while importing CSV file despite varchar(MAX) being used for each column(尽管每列都使用了 varchar(MAX),但在导入 CSV 文件时 SQL Server 中出现错误)
                  How can I import an Excel file into SQL Server?(如何将 Excel 文件导入 SQL Server?)
                  Export table to file with column headers (column names) using the bcp utility and SQL Server 2008(使用 bcp 实用程序和 SQL Server 2008 将表导出到带有列标题(列名称)的文件)
                  Concat field value to string in SQL Server(将字段值连接到 SQL Server 中的字符串)
                  SQL Server Bulk insert of CSV file with inconsistent quotes(SQL Server 批量插入带有不一致引号的 CSV 文件)
                    <bdo id='nWQPp'></bdo><ul id='nWQPp'></ul>
                    <i id='nWQPp'><tr id='nWQPp'><dt id='nWQPp'><q id='nWQPp'><span id='nWQPp'><b id='nWQPp'><form id='nWQPp'><ins id='nWQPp'></ins><ul id='nWQPp'></ul><sub id='nWQPp'></sub></form><legend id='nWQPp'></legend><bdo id='nWQPp'><pre id='nWQPp'><center id='nWQPp'></center></pre></bdo></b><th id='nWQPp'></th></span></q></dt></tr></i><div id='nWQPp'><tfoot id='nWQPp'></tfoot><dl id='nWQPp'><fieldset id='nWQPp'></fieldset></dl></div>

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

                    1. <legend id='nWQPp'><style id='nWQPp'><dir id='nWQPp'><q id='nWQPp'></q></dir></style></legend>
                          <tbody id='nWQPp'></tbody>

                            <tfoot id='nWQPp'></tfoot>