• <tfoot id='zxFpi'></tfoot>
      <bdo id='zxFpi'></bdo><ul id='zxFpi'></ul>
    1. <small id='zxFpi'></small><noframes id='zxFpi'>

    2. <legend id='zxFpi'><style id='zxFpi'><dir id='zxFpi'><q id='zxFpi'></q></dir></style></legend>

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

        如何在sqlite django ORM中实现have子句

        时间:2023-10-08

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

              <tfoot id='PkGSJ'></tfoot><legend id='PkGSJ'><style id='PkGSJ'><dir id='PkGSJ'><q id='PkGSJ'></q></dir></style></legend>

                  <tbody id='PkGSJ'></tbody>

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

                • 本文介绍了如何在sqlite django ORM中实现have子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我已经编写了 django sqlite orm 语法来检索特定的记录集:

                  I've written django sqlite orm syntax to retrieve particular set of records:

                  from django.db.models.aggregates import Count
                  
                  JobStatus.objects.filter(
                      status='PRF'
                  ).values_list(
                      'job', flat=True
                  ).order_by(
                      'job'
                  ).aggregate(
                      Count(status)__gt=3
                  ).distinct()
                  

                  但它给了我一个错误,这个语法的 sql 对我来说很好.

                  But it gives me an error and the sql equivalent for this syntax works fine for me.

                  这是我的 sql 等价物.

                  This is my sql equivalent.

                  SELECT *
                    FROM tracker_jobstatus
                   WHERE status = 'PRF'
                   GROUP BY job_id
                  HAVING COUNT(status) > 3;
                  

                  我得到的结果如下

                  +----+--------+--------+---------+---------------------+---------+
                  | id | job_id | status | comment | date_and_time       | user_id |
                  +----+--------+--------+---------+---------------------+---------+
                  | 13 |      3 | PRF    |         | 2012-11-12 13:16:00 |       1 |
                  | 31 |      4 | PRF    |         | 2012-11-12 13:48:00 |       1 |
                  +----+--------+--------+---------+---------------------+---------+
                  

                  我无法为此找到等效的 django sqlite.

                  I'm unable to find the django sqlite equivalent for this.

                  如果有人能提供帮助,我将不胜感激.

                  I will be very grateful if anyone can help.

                  推荐答案

                  我终于想通了.ORM 语法是这样的.

                  Finally I've managed to figure it out. The ORM syntax is something like this.

                  from django.db.models.aggregates import Count
                  
                  JobStatus.objects.filter(
                      status='PRF'
                  ).values_list(
                      'job', flat=True
                  ).order_by(
                      'job'
                  ).annotate(
                      count_status=Count('status')
                  ).filter(
                      count_status__gt=1
                  ).distinct()
                  

                  这篇关于如何在sqlite django ORM中实现have子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Django“无法打开数据库文件" 下一篇:使用旧数据库在 django 项目中使用复合主键

                  相关文章

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

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

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