• <small id='Zw0kk'></small><noframes id='Zw0kk'>

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

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

      <tfoot id='Zw0kk'></tfoot>

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

        在不同的列上两次加入同一个表

        joining the same table twice on different columns(在不同的列上两次加入同一个表)

        • <tfoot id='oD3wV'></tfoot>
            <tbody id='oD3wV'></tbody>

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

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

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

                  本文介绍了在不同的列上两次加入同一个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 user 表和一个 complaint 表.

                  I've got a user table and a complaint table.

                  complaint 表的结构如下:

                  [opened_by]   [complaint_text]   [closed_by]
                   (user_id)         (text)         (user_id)
                   (user_id)         (text)         (user_id)
                   (user_id)         (text)         (user_id)
                  

                  所有用户,包括 complainerscomplaint-resolvers 都位于表 user 中.

                  All users, both the complainers and complaint-resolvers are located in table user.

                  如何编写查询以显示两列的用户名?

                  How do I write a query to show the username for both columns?

                  这给了我一个:

                  SELECT user.username, complaint.complaint_text
                  FROM complaint
                  LEFT JOIN user ON user.user_id=complaint.opened_by
                  

                  但我不知道怎么写,所以 _by 列都显示用户名而不是 ID.

                  but I don't know how to write it so both _by columns show usernames rather than IDs.

                  推荐答案

                  SELECT 
                       complaint.complaint_text, 
                       A.username, 
                       B.username
                  FROM 
                       complaint 
                       LEFT JOIN user A ON A.user_id=complaint.opened_by 
                       LEFT JOIN user B ON B.user_id=complaint.closed_by
                  

                  这篇关于在不同的列上两次加入同一个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 to update a record using sequelize for node?(如何使用节点的 sequelize 更新记录?)
                  How to provide a mysql database connection in single file in nodejs(如何在 nodejs 中的单个文件中提供 mysql 数据库连接)
                  Defining a one-to-one relationship in SQL Server(在 SQL Server 中定义一对一关系)
                  Looping Over Result Sets in MySQL(在 MySQL 中循环结果集)
                  <tfoot id='zoxRr'></tfoot>

                        <bdo id='zoxRr'></bdo><ul id='zoxRr'></ul>

                        <legend id='zoxRr'><style id='zoxRr'><dir id='zoxRr'><q id='zoxRr'></q></dir></style></legend>
                      • <small id='zoxRr'></small><noframes id='zoxRr'>

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