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

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

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

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

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

      2. 如何使用 group-concat mysql 创建 json 格式?

        How create json format with group-concat mysql?(如何使用 group-concat mysql 创建 json 格式?)

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

            <small id='5MpJR'></small><noframes id='5MpJR'>

              1. <legend id='5MpJR'><style id='5MpJR'><dir id='5MpJR'><q id='5MpJR'></q></dir></style></legend><tfoot id='5MpJR'></tfoot>

                  <bdo id='5MpJR'></bdo><ul id='5MpJR'></ul>
                  本文介绍了如何使用 group-concat mysql 创建 json 格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何用group-concat mysql创建json格式?

                  How create json format with group-concat mysql?

                  (我使用 MySQL)

                  (I use MySQL)

                  示例 1:

                  表 1:

                  email            |    name  |   phone
                  -------------------------------------
                  my1@gmail.com    | Ben      | 6555333
                  my2@gmail.com    | Tom      | 2322452
                  my2@gmail.com    | Dan      | 8768768
                  my1@gmail.com    | Joi      | 3434356
                  

                  像没有给我格式的语法代码:

                  like syntax code that not give me the format:

                  select email, group-concat(name,phone) as list from table1 
                  group by email
                  

                  我需要的输出:

                  email         |    list
                  ------------------------------------------------
                  my1@gmail.com |  {name:"Ben",phone:"6555333"},{name:"Joi",phone:"3434356"}
                  my2@gmail.com |  {name:"Tom",phone:"2322452"},{name:"Dan",phone:"8768768"}
                  

                  谢谢

                  推荐答案

                  试试这个查询 -

                  SELECT
                    email,
                    GROUP_CONCAT(CONCAT('{name:"', name, '", phone:"',phone,'"}')) list
                  FROM
                    table1
                  GROUP BY
                    email;
                  

                  JSON 格式结果 -

                  JSON format result -

                  +---------------+-------------------------------------------------------------+
                  | email         | list                                                        |
                  +---------------+-------------------------------------------------------------+
                  | my1@gmail.com | {name:"Ben", phone:"6555333"},{name:"Joi", phone:"3434356"} |
                  | my2@gmail.com | {name:"Tom", phone:"2322452"},{name:"Dan", phone:"8768768"} |
                  +---------------+-------------------------------------------------------------+
                  

                  这篇关于如何使用 group-concat mysql 创建 json 格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Bogus foreign key constraint fail(虚假外键约束失败)
                  how to get last insert id after insert query in codeigniter active record(如何在codeigniter活动记录中插入查询后获取最后一个插入ID)
                  Force InnoDB to recheck foreign keys on a table/tables?(强制 InnoDB 重新检查表/表上的外键?)
                  How to auto generate migrations with Sequelize CLI from Sequelize models?(如何使用 Sequelize CLI 从 Sequelize 模型自动生成迁移?)
                  Clear MySQL query cache without restarting server(无需重启服务器即可清除 MySQL 查询缓存)
                  ALTER TABLE to add a composite primary key(ALTER TABLE 添加复合主键)

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

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

                            <tfoot id='Qf9Pp'></tfoot>