当前位置:网站首页>ORM--分组查询,聚合查询,查询集QuerySet对象特性
ORM--分组查询,聚合查询,查询集QuerySet对象特性
2022-07-07 07:17:00 【chuntian_tester】
1.分组查询
1.1.使用 QuerySet对象.values(‘父表主键id’).annotate(聚合函数(‘从表模型类名小写')
1.2.会自动连接主从表,以外键字段作为分组条件

2.聚合运算
2.1.使用 QuerySet对象.aggregate(聚合函数('字段名')) 方法,返回字典数据
2.2.返回的字典数据中的key为 字段名__聚合函数名 小写
2.3.可以使用关键参数形式,返回的字典数据中的key为关键字参数名
qs = Projects.objects.filter(full_name__contains='x').aggregate(Count("id"))

qs = Projects.objects.filter(full_name__contains='x').aggregate(count=Count("id"))

3.查询集QuerySet对象的特性:
3.1 支持链式调用
可以在查询集上多次调用filter(),exclude()方法
3.2 惰性查询
仅仅在使用数据时才执行Sql语句,为了提升数据库的读写性能
3.3 会执行Sql语句场景:
len(),count(),通过索引取值,切片,for循环,print等
边栏推荐
- phpcms实现PC网站接入微信Native支付
- How to use clipboard JS library implements copy and cut function
- Application of C # XML
- Create an int type array with a length of 6. The values of the array elements are required to be between 1-30 and are assigned randomly. At the same time, the values of the required elements are diffe
- Liunx command
- Writing file types generated by C language
- Communication mode between processes
- 【原创】程序员团队管理的核心是什么?
- How to solve the problem of golang select mechanism and timeout
- Garbage disposal method based on the separation of smart city and storage and living digital home mode
猜你喜欢

Pit encountered by vs2015 under win7 (successful)

Performance optimization record of the company's product "yunzhujia"

CSDN salary increase technology - learn about the use of several common logic controllers of JMeter

“十二星座女神降临”全新活动推出
![[bw16 application] Anxin can realize mqtt communication with bw16 module / development board at instruction](/img/7f/d0917366c68865222154d82b9e7b40.png)
[bw16 application] Anxin can realize mqtt communication with bw16 module / development board at instruction
![[4G/5G/6G专题基础-146]: 6G总体愿景与潜在关键技术白皮书解读-1-总体愿景](/img/fd/5e8f74da25d9c5f7bd69dd1cfdcd61.png)
[4G/5G/6G专题基础-146]: 6G总体愿景与潜在关键技术白皮书解读-1-总体愿景

Arcgis操作: 批量修改属性表

Lesson 1: finding the minimum of a matrix

Applet popup half angle mask layer

Pytest learning - dayone
随机推荐
C# Socke 服务器,客户端,UDP
phpcms实现PC网站接入微信Native支付
Addition, deletion, modification and query of ThinkPHP database
Do you have a boss to help look at this error report and what troubleshooting ideas are there? Oracle CDC 2.2.1 flick 1.14.4
Bean 作⽤域和⽣命周期
AI从感知走向智能认知
2020CCPC威海 J - Steins;Game (sg函数、线性基)
web3.0系列之分布式存储IPFS
Internship log - day04
CDZSC_ 2022 winter vacation personal training match level 21 (2)
Sqlplus garbled code problem, find the solution
哈夫曼编码压缩文件
用flinksql的方式 写进 sr的表,发现需要删除的数据没有删除,参照文档https://do
C socke server, client, UDP
Analyze Android event distribution mechanism according to popular interview questions (II) -- event conflict analysis and handling
印象笔记终于支持默认markdown预览模式
字节跳动 Kitex 在森马电商场景的落地实践
[bw16 application] Anxin can realize mqtt communication with bw16 module / development board at instruction
Application of C # XML
2016 CCPC Hangzhou Onsite