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

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

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

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

        GROUP_CONCAT 在 Django 中的等价物

        GROUP_CONCAT equivalent in Django(GROUP_CONCAT 在 Django 中的等价物)

          <tbody id='xfdpS'></tbody>

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

            <tfoot id='xfdpS'></tfoot>

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

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

                  问题描述

                  限时送ChatGPT账号..

                  假设我有一张名为 fruits 的表格:

                  Say I have the following table called fruits:

                  id | type   | name
                  -----------------
                   0 | apple  | fuji
                   1 | apple  | mac
                   2 | orange | navel
                  

                  我的目标是最终得出不同types的数量和一个以逗号分隔的名称列表:

                  My goal is to ultimately come up with a count of the different types and a comma-delimited list of the names:

                  apple, 2, "fuji,mac"
                  orange, 1, "navel"
                  

                  这可以通过 MySQL 中的 GROUP_CONCAT 轻松完成,但我在使用 Django 等效项时遇到了麻烦.这是我到目前为止所拥有的,但我缺少 GROUP_CONCAT 的东西:

                  This can be easily done with GROUP_CONCAT in MySQL but I'm having trouble with the Django equivalent. This is what I have so far but I am missing the GROUP_CONCAT stuff:

                  query_set = Fruits.objects.values('type').annotate(count=Count('type')).order_by('-count')
                  

                  如果可能,我想避免使用原始 SQL 查询.

                  I would like to avoid using raw SQL queries if possible.

                  任何帮助将不胜感激!

                  谢谢!=)

                  推荐答案

                  Django ORM 不支持这个;如果您不想使用原始 SQL,那么您需要 分组并加入.

                  The Django ORM does not support this; if you don't want to use raw SQL then you'll need to group and join.

                  这篇关于GROUP_CONCAT 在 Django 中的等价物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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?)
                • <small id='s1BSU'></small><noframes id='s1BSU'>

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

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

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