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

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

    <tfoot id='XMkaU'></tfoot>

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

    1. MySQL:多行作为逗号分隔的单行

      MySQL : Multiple row as comma separated single row(MySQL:多行作为逗号分隔的单行)
        <i id='Wa3IV'><tr id='Wa3IV'><dt id='Wa3IV'><q id='Wa3IV'><span id='Wa3IV'><b id='Wa3IV'><form id='Wa3IV'><ins id='Wa3IV'></ins><ul id='Wa3IV'></ul><sub id='Wa3IV'></sub></form><legend id='Wa3IV'></legend><bdo id='Wa3IV'><pre id='Wa3IV'><center id='Wa3IV'></center></pre></bdo></b><th id='Wa3IV'></th></span></q></dt></tr></i><div id='Wa3IV'><tfoot id='Wa3IV'></tfoot><dl id='Wa3IV'><fieldset id='Wa3IV'></fieldset></dl></div>
      • <small id='Wa3IV'></small><noframes id='Wa3IV'>

          <tfoot id='Wa3IV'></tfoot>

              <tbody id='Wa3IV'></tbody>
              • <bdo id='Wa3IV'></bdo><ul id='Wa3IV'></ul>

                <legend id='Wa3IV'><style id='Wa3IV'><dir id='Wa3IV'><q id='Wa3IV'></q></dir></style></legend>
              • 本文介绍了MySQL:多行作为逗号分隔的单行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我有两个表:DISH 和 DISH_HAS_DISHES.Dish 表包含所有菜肴,Dish_has_dishes"表与Dish"表是一对多的关系.IE.一道菜可以有多道菜.例如

                I have two tables : DISH and DISH_HAS_DISHES. Dish table has all the dishes and "Dish_has_dishes" table has a one-to-many relationship with "Dish" table. I.e. a dish can have multiple dishes. For example

                :

                dish_id   dish_name
                1         dish_1
                2         dish_2
                3         dish_3
                4         dish_4
                

                DISH_HAS_DISHES:

                meal_id   dish_id
                1         2
                1         3
                1         4
                

                这里的meal_id和dish_id都是DISH表中的ID.现在我想要这样的格式:

                Here meal_id and dish_id both are IDs from DISH table. Now I want a format like this:

                meal_id     dish_ids     dish_names
                1           2,3,4        dish_2, dish_3, dish_4
                

                那是每顿饭用逗号分隔的菜名和菜名.怎么做?

                That is comma separated dish id and names for each meal. How to do that?

                推荐答案

                使用 GROUP_CONCAT FUNCTION

                Use GROUP_CONCAT FUNCTION

                http://dev.mysql.com/tech-resources/articles/4.1/grab-bag.html

                 SELEct m.meal_Id, 
                        GROUP_CONCAT(dish_id) dish_ids, 
                        GROUP_CONCAT(dish_name) dish_names
                 FROM DISH_HAS_DISHES m JOIN DISH d ON (m.dish_id = d.dish_id)
                 GROUP BY meal_Id
                

                这篇关于MySQL:多行作为逗号分隔的单行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                Can#39;t Create Entity Data Model - using MySql and EF6(无法创建实体数据模型 - 使用 MySql 和 EF6)
                MySQL select with CONCAT condition(MySQL选择与CONCAT条件)
                Capitalize first letter of each word, in existing table(将现有表格中每个单词的首字母大写)
                How to retrieve SQL result column value using column name in Python?(如何在 Python 中使用列名检索 SQL 结果列值?)
                Update row with data from another row in the same table(使用同一表中另一行的数据更新行)
                Exporting results of a Mysql query to excel?(将 Mysql 查询的结果导出到 excel?)
              • <tfoot id='u7w3k'></tfoot>
                  <tbody id='u7w3k'></tbody>

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

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

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

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