• <tfoot id='kiRr4'></tfoot>

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

    1. <small id='kiRr4'></small><noframes id='kiRr4'>

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

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

        MySQL 中 GROUP_CONCAT 的反面是什么?

        时间:2023-08-18
          <tfoot id='XlYC2'></tfoot>
            • <bdo id='XlYC2'></bdo><ul id='XlYC2'></ul>
                <tbody id='XlYC2'></tbody>

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

                • <legend id='XlYC2'><style id='XlYC2'><dir id='XlYC2'><q id='XlYC2'></q></dir></style></legend>
                • <i id='XlYC2'><tr id='XlYC2'><dt id='XlYC2'><q id='XlYC2'><span id='XlYC2'><b id='XlYC2'><form id='XlYC2'><ins id='XlYC2'></ins><ul id='XlYC2'></ul><sub id='XlYC2'></sub></form><legend id='XlYC2'></legend><bdo id='XlYC2'><pre id='XlYC2'><center id='XlYC2'></center></pre></bdo></b><th id='XlYC2'></th></span></q></dt></tr></i><div id='XlYC2'><tfoot id='XlYC2'></tfoot><dl id='XlYC2'><fieldset id='XlYC2'></fieldset></dl></div>
                  本文介绍了MySQL 中 GROUP_CONCAT 的反面是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我似乎经常遇到这个问题,我的数据格式如下:

                  I seem to come against this problem a lot, where I have data that's formatted like this:

                  +----+----------------------+
                  | id | colors               |
                  +----+----------------------+
                  | 1  | Red,Green,Blue       |
                  | 2  | Orangered,Periwinkle |
                  +----+----------------------+
                  

                  但我希望它的格式如下:

                  but I want it formatted like this:

                  +----+------------+
                  | id | colors     |
                  +----+------------+
                  | 1  | Red        |
                  | 1  | Green      |
                  | 1  | Blue       |
                  | 2  | Orangered  |
                  | 2  | Periwinkle |
                  +----+------------+
                  

                  有什么好办法吗?这种操作叫什么?

                  Is there a good way to do this? What is this kind of operation even called?

                  推荐答案

                  我认为这是你需要的(存储过程):Mysql 将列字符串拆分成行

                  I think it is what you need (stored procedure) : Mysql split column string into rows

                  DELIMITER $$
                  
                  DROP PROCEDURE IF EXISTS explode_table $$
                  CREATE PROCEDURE explode_table(bound VARCHAR(255))
                  
                  BEGIN
                  
                  DECLARE id INT DEFAULT 0;
                  DECLARE value TEXT;
                  DECLARE occurance INT DEFAULT 0;
                  DECLARE i INT DEFAULT 0;
                  DECLARE splitted_value INT;
                  DECLARE done INT DEFAULT 0;
                  DECLARE cur1 CURSOR FOR SELECT table1.id, table1.value
                                                       FROM table1
                                                       WHERE table1.value != '';
                  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
                  
                  DROP TEMPORARY TABLE IF EXISTS table2;
                  CREATE TEMPORARY TABLE table2(
                  `id` INT NOT NULL,
                  `value` VARCHAR(255) NOT NULL
                  ) ENGINE=Memory;
                  
                  OPEN cur1;
                    read_loop: LOOP
                      FETCH cur1 INTO id, value;
                      IF done THEN
                        LEAVE read_loop;
                      END IF;
                  
                      SET occurance = (SELECT LENGTH(value)
                                               - LENGTH(REPLACE(value, bound, ''))
                                               +1);
                      SET i=1;
                      WHILE i <= occurance DO
                        SET splitted_value =
                        (SELECT REPLACE(SUBSTRING(SUBSTRING_INDEX(value, bound, i),
                        LENGTH(SUBSTRING_INDEX(value, bound, i - 1)) + 1), ',', ''));
                  
                        INSERT INTO table2 VALUES (id, splitted_value);
                        SET i = i + 1;
                  
                      END WHILE;
                    END LOOP;
                  
                    SELECT * FROM table2;
                   CLOSE cur1;
                   END; $$
                  

                  这篇关于MySQL 中 GROUP_CONCAT 的反面是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:MySQL 偏移无限行 下一篇:返回 IN 值的默认结果,不管

                  相关文章

                  最新文章

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

                    <tfoot id='JnVkN'></tfoot>
                    1. <small id='JnVkN'></small><noframes id='JnVkN'>

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