当前位置:网站首页>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等
边栏推荐
- Octopus future star won a reward of 250000 US dollars | Octopus accelerator 2022 summer entrepreneurship camp came to a successful conclusion
- What development models did you know during the interview? Just read this one
- 请教个问题,我用sql-client起了个同步任务,从MySQL同步到ADB,历史数据有正常同步过去
- Performance optimization record of the company's product "yunzhujia"
- 使用BigDecimal的坑
- Basic use of JMeter to proficiency (I) creation and testing of the first task thread from installation
- There is a problem using Chinese characters in SQL. Who has encountered it? Such as value & lt; & gt;` None`
- Arthas simple instructions
- web3.0系列之分布式存储IPFS
- PostgreSQL创建触发器的时候报错,
猜你喜欢
![[untitled]](/img/5b/61efbaded29250bc8d921b0cf087c8.png)
[untitled]

中国首款电音音频类“山野电音”数藏发售来了!

PLC信号处理系列之开关量信号防抖FB

Sqlplus garbled code problem, find the solution

# Arthas 简单使用说明

Arcgis操作: 批量修改属性表

小程序实现页面多级来回切换支持滑动和点击操作

How will fashion brands enter the meta universe?

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专题基础-147]: 6G总体愿景与潜在关键技术白皮书解读-2-6G发展的宏观驱动力
如何成为一名高级数字 IC 设计工程师(1-6)Verilog 编码语法篇:经典数字 IC 设计
Internship log - day07
细说Mysql MVCC多版本控制
根据热门面试题分析Android事件分发机制(一)
AI从感知走向智能认知
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
小程序实现页面多级来回切换支持滑动和点击操作
PostgreSQL reports an error when creating a trigger,
高斯消元
使用BigDecimal的坑
Octopus future star won a reward of 250000 US dollars | Octopus accelerator 2022 summer entrepreneurship camp came to a successful conclusion
ViewPager2和VIewPager的區別以及ViewPager2實現輪播圖
大佬们,请问 MySQL-CDC 有什么办法将 upsert 消息转换为 append only 消
Scratch crawler mysql, Django, etc
Difference between process and thread
剑指 Offer II 107. 矩阵中的距离
2020CCPC威海 J - Steins;Game (sg函数、线性基)
Lesson 1: finding the minimum of a matrix
Analyze Android event distribution mechanism according to popular interview questions (II) -- event conflict analysis and handling