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

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

      <tfoot id='F30jf'></tfoot>
        <bdo id='F30jf'></bdo><ul id='F30jf'></ul>

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

        MySQL:GROUP_CONCAT 与 LEFT JOIN

        MySQL: GROUP_CONCAT with LEFT JOIN(MySQL:GROUP_CONCAT 与 LEFT JOIN)
      2. <i id='MUrT9'><tr id='MUrT9'><dt id='MUrT9'><q id='MUrT9'><span id='MUrT9'><b id='MUrT9'><form id='MUrT9'><ins id='MUrT9'></ins><ul id='MUrT9'></ul><sub id='MUrT9'></sub></form><legend id='MUrT9'></legend><bdo id='MUrT9'><pre id='MUrT9'><center id='MUrT9'></center></pre></bdo></b><th id='MUrT9'></th></span></q></dt></tr></i><div id='MUrT9'><tfoot id='MUrT9'></tfoot><dl id='MUrT9'><fieldset id='MUrT9'></fieldset></dl></div>
      3. <small id='MUrT9'></small><noframes id='MUrT9'>

      4. <legend id='MUrT9'><style id='MUrT9'><dir id='MUrT9'><q id='MUrT9'></q></dir></style></legend>
        <tfoot id='MUrT9'></tfoot>
          <tbody id='MUrT9'></tbody>
            <bdo id='MUrT9'></bdo><ul id='MUrT9'></ul>

                • 本文介绍了MySQL:GROUP_CONCAT 与 LEFT JOIN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在使用 MySQL 的GROUP_CONCAT"函数时遇到问题.我将使用一个简单的帮助台数据库来说明我的问题:

                  I'm experiencing a problem with MySQL's "GROUP_CONCAT" function. I will illustrate my problem using a simple help desk database:

                  CREATE TABLE Tickets (
                   id INTEGER NOT NULL PRIMARY KEY,
                   requester_name VARCHAR(255) NOT NULL,
                   description TEXT NOT NULL);
                  
                  CREATE TABLE Solutions (
                   id INTEGER NOT NULL PRIMARY KEY,
                   ticket_id INTEGER NOT NULL,
                   technician_name VARCHAR(255) NOT NULL,
                   solution TEXT NOT NULL,
                   FOREIGN KEY (ticket_id) REFERENCES Tickets.id);
                  
                  INSERT INTO Tickets VALUES(1, 'John Doe', 'My computer is not booting.');
                  INSERT INTO Tickets VALUES(2, 'Jane Doe', 'My browser keeps crashing.');
                  INSERT INTO Solutions VALUES(1, 1, 'Technician A', 'I tried to solve this but was unable to. I will pass this on to Technician B since he is more experienced than I am.');
                  INSERT INTO Solutions VALUES(2, 1, 'Technician B', 'I reseated the RAM and that fixed the problem.');
                  INSERT INTO Solutions VALUES(3, 2, 'Technician A', 'I was unable to figure this out. I will again pass this on to Technician B.');
                  INSERT INTO Solutions VALUES(4, 2, 'Technician B', 'I re-installed the browser and that fixed the problem.');
                  

                  请注意,此帮助台数据库有两张票,每张票都有两个解决方案条目.我的目标是使用 SELECT 语句创建数据库中所有票证及其对应解决方案条目的列表.这是我正在使用的 SELECT 语句:

                  Notice that this help desk database has two tickets, each with two solution entries. My goal is to use a SELECT statement to create a list of all of the tickets in the database with their corrosponding solution entries. This is the SELECT statement I'm using:

                  SELECT Tickets.*, GROUP_CONCAT(Solutions.solution) AS CombinedSolutions
                  FROM Tickets
                  LEFT JOIN Solutions ON Tickets.id = Solutions.ticket_id
                  ORDER BY Tickets.id;
                  

                  上述 SELECT 语句的问题是它只返回一行:

                  The problem with the above SELECT statement is it's returning only one row:

                  id: 1
                  requester_name: John Doe
                  description: My computer is not booting.
                  CombinedSolutions: I tried to solve this but was unable to. I will pass this on to Technician B since he is more experienced than I am.,I reseated the RAM and that fixed the problem.,I was unable to figure this out. I will again pass this on to Technician B.,I re-installed the browser and that fixed the problem.
                  

                  请注意,它返回了票证 1 的信息以及票证 1 和票证 2 的解决方案条目.

                  Notice that it's returning ticket 1's information with both ticket 1's and ticket 2's solution entries.

                  我做错了什么?谢谢!

                  推荐答案

                  使用:

                     SELECT t.*,
                            x.combinedsolutions
                       FROM TICKETS t
                  LEFT JOIN (SELECT s.ticket_id,
                                    GROUP_CONCAT(s.soution) AS combinedsolutions
                               FROM SOLUTIONS s 
                           GROUP BY s.ticket_id) x ON x.ticket_id = t.ticket_id
                  

                  替代:

                     SELECT t.*,
                            (SELECT GROUP_CONCAT(s.soution)
                               FROM SOLUTIONS s 
                              WHERE s.ticket_id = t.ticket_id) AS combinedsolutions
                       FROM TICKETS t
                  

                  这篇关于MySQL:GROUP_CONCAT 与 LEFT JOIN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  SQL query to group by day(按天分组的 SQL 查询)
                  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 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
                      <bdo id='WdYvQ'></bdo><ul id='WdYvQ'></ul>
                      <i id='WdYvQ'><tr id='WdYvQ'><dt id='WdYvQ'><q id='WdYvQ'><span id='WdYvQ'><b id='WdYvQ'><form id='WdYvQ'><ins id='WdYvQ'></ins><ul id='WdYvQ'></ul><sub id='WdYvQ'></sub></form><legend id='WdYvQ'></legend><bdo id='WdYvQ'><pre id='WdYvQ'><center id='WdYvQ'></center></pre></bdo></b><th id='WdYvQ'></th></span></q></dt></tr></i><div id='WdYvQ'><tfoot id='WdYvQ'></tfoot><dl id='WdYvQ'><fieldset id='WdYvQ'></fieldset></dl></div>
                        <tbody id='WdYvQ'></tbody>
                      <tfoot id='WdYvQ'></tfoot>

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

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